mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1345842 - Add Ignore to allow ignore elements in Tie. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68742 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
50b327f08e
commit
62d6d7db0e
29
mfbt/Tuple.h
29
mfbt/Tuple.h
@ -67,6 +67,19 @@ struct CheckConvertibility<Group<SourceTypes...>, Group<TargetTypes...>>
|
||||
sizeof...(SourceTypes) ==
|
||||
sizeof...(TargetTypes)> {};
|
||||
|
||||
/*
|
||||
* Helper type for Tie(args...) to allow ignoring specific elements
|
||||
* during Tie unpacking. Supports assignment from any type.
|
||||
*
|
||||
* Not for direct usage; instead, use mozilla::Ignore in calls to Tie.
|
||||
*/
|
||||
struct IgnoreImpl {
|
||||
template <typename T>
|
||||
constexpr const IgnoreImpl& operator=(const T&) const {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* TupleImpl is a helper class used to implement mozilla::Tuple.
|
||||
* It represents one node in a recursive inheritance hierarchy.
|
||||
@ -463,6 +476,22 @@ inline Tuple<std::decay_t<Elements>...> MakeTuple(Elements&&... aElements) {
|
||||
return Tuple<std::decay_t<Elements>...>(std::forward<Elements>(aElements)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper placholder to allow ignoring specific elements during Tie unpacking.
|
||||
* Can be used with any type and any number of elements in a call to Tie.
|
||||
*
|
||||
* Usage of Ignore with Tie is equivalent to using std::ignore with
|
||||
* std::tie.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* int i;
|
||||
* float f;
|
||||
* char c;
|
||||
* Tie(i, Ignore, f, c, Ignore) = FunctionThatReturnsATuple();
|
||||
*/
|
||||
constexpr detail::IgnoreImpl Ignore;
|
||||
|
||||
/**
|
||||
* A convenience function for constructing a tuple of references to a
|
||||
* sequence of variables. Since assignments to the elements of the tuple
|
||||
|
@ -281,6 +281,19 @@ static bool TestTie() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool TestTieIgnore() {
|
||||
int i;
|
||||
char c;
|
||||
Tuple<int, float, char> rhs1(42, 0.5f, 'c');
|
||||
|
||||
Tie(i, mozilla::Ignore, c) = rhs1;
|
||||
|
||||
CHECK(i == Get<0>(rhs1));
|
||||
CHECK(c == Get<2>(rhs1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
TestConstruction();
|
||||
TestConstructionFromMozPair();
|
||||
@ -291,6 +304,7 @@ int main() {
|
||||
TestGet();
|
||||
TestMakeTuple();
|
||||
TestTie();
|
||||
TestTieIgnore();
|
||||
TestTieMozPair();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user