Bug 1622166 - Change variadic functions from the old recursive way using Fold expressions r=gerald,jld

Differential Revision: https://phabricator.services.mozilla.com/D70431
This commit is contained in:
nicolaspacheco 2020-05-14 16:31:17 +00:00
parent 91e4aa862f
commit 72803335c4
2 changed files with 7 additions and 20 deletions

View File

@ -19,8 +19,4 @@ bool ByteLengthIsValid(uint32_t aNumElements, size_t aElementSize,
return true;
}
void WriteParams(Message* aMsg) {}
bool ReadParams(const Message* aMsg, PickleIterator* aIter) { return true; }
} // namespace IPC

View File

@ -1269,24 +1269,15 @@ struct BitfieldHelper {
// WriteParams(aMsg, aParam.foo, aParam.bar, aParam.baz)
// ReadParams(aMsg, aIter, aParam.foo, aParam.bar, aParam.baz)
// Base case
void WriteParams(Message* aMsg);
template <typename T0, typename... Tn>
static void WriteParams(Message* aMsg, const T0& aArg,
const Tn&... aRemainingArgs) {
WriteParam(aMsg, aArg); // Write first arg
WriteParams(aMsg, aRemainingArgs...); // Recurse for the rest
template <typename... Ts>
static void WriteParams(Message* aMsg, const Ts&... aArgs) {
(WriteParam(aMsg, aArgs), ...);
}
// Base case
bool ReadParams(const Message* aMsg, PickleIterator* aIter);
template <typename T0, typename... Tn>
static bool ReadParams(const Message* aMsg, PickleIterator* aIter, T0& aArg,
Tn&... aRemainingArgs) {
return ReadParam(aMsg, aIter, &aArg) && // Read first arg
ReadParams(aMsg, aIter, aRemainingArgs...); // Recurse for the rest
template <typename... Ts>
static bool ReadParams(const Message* aMsg, PickleIterator* aIter,
Ts&... aArgs) {
return (ReadParam(aMsg, aIter, &aArgs) && ...);
}
// Macros that allow syntax like: