#include <tuple.h>
Tuple provides in-place static storage for elements of arbitrary types. It is similar to a pair, but supports a variable number of elements. The memory layout is identical to a struct with the same member types:
Tuples allow to create generic classes which store a variable number of member-like types that can be initialized from a parameter pack. Example:
Tuples can also reduce the amount of boilerplate code when storing struct-like entries in containers like BaseArray, because they already come with the full range of constructors, assignment operators and comparison operators defined.
Another use case is simplifying multiple return values from a function by wrapping them in a tuple and using Tie to map them to variables:
Since tuple elements are unnamed and can only be accessed by index or unique type, when using them in interfaces you should always consider whether using a struct with named elements would make things more obvious.
T | Element types. |
Public Types | |
using | Pack = ParameterPack< T... > |
![]() | |
using | Pack = ParameterPack< T... > |
Public Member Functions | |
Tuple ()=default | |
template<typename... U, typename = typename std::enable_if<And<STD_IS_REPLACEMENT(constructible, T, const U&)...>::value>::type> | |
Tuple (const Tuple< U... > &src) | |
template<typename... U, typename = typename std::enable_if<And<STD_IS_REPLACEMENT(constructible, T, U&&)...>::value>::type> | |
Tuple (Tuple< U... > &&src) | |
constexpr MAXON_IMPLICIT | Tuple (const typename std::conditional< COPYABLE, T, volatile DummyParamType >::type &... x) |
template<typename... U, typename = typename std::enable_if<And<STD_IS_REPLACEMENT(constructible, T, U&&)...>::value>::type> | |
MAXON_IMPLICIT | Tuple (U &&... x) |
template<typename... U> | |
Tuple & | operator= (const Tuple< U... > &src) |
template<typename... U> | |
Tuple & | operator= (Tuple< U... > &&src) |
Result< void > | CopyFrom (const typename std::conditional< COPYABLE, DummyParamType, Tuple >::type &src) |
SFINAEHelper< String, T... >::type | ToString (const FormatStatement *format=nullptr) const |
template<typename HASH = DefaultCompare> | |
HashInt | GetHashCode () const |
template<typename HASH = DefaultCompare> | |
UniqueHash | GetUniqueHashCode () const |
template<Int I> | |
std::add_const< typename Pack::template At< I >::type >::type & | Get () const |
template<Int I> | |
Pack::template At< I >::type & | Get () |
template<typename ELEMENTTYPE > | |
auto | Get () const -> const ELEMENTTYPE & |
template<typename ELEMENTTYPE > | |
auto | Get () -> ELEMENTTYPE & |
Bool | operator== (const Tuple &other) const |
Bool | operator< (const Tuple &other) const |
MAXON_OPERATOR_COMPARISON (Tuple) | |
![]() | |
TupleStorage ()=default | |
TupleStorage (std::index_sequence< I... > *, ARGS &&... args) | |
MAXON_DECLARE_CONDITIONAL_COPY_CONSTRUCTOR (TupleStorage, COPY_CONSTRUCTIBLE) | |
MAXON_DECLARE_CONDITIONAL_COPY_ASSIGNMENT (TupleStorage, COPY_ASSIGNABLE) | |
MAXON_DECLARE_CONDITIONAL_MOVE_CONSTRUCTOR (TupleStorage, MOVE_CONSTRUCTIBLE) | |
MAXON_DECLARE_CONDITIONAL_MOVE_ASSIGNMENT (TupleStorage, MOVE_ASSIGNABLE) | |
![]() | |
TupleStorageBase ()=delete | |
~TupleStorageBase () | |
Static Public Member Functions | |
static constexpr Bool | TriviallyHashable () |
Private Types | |
using | Super = maxon::details::TupleStorage< T... > |
using | IndexSequence = std::index_sequence_for< T... > |
Private Member Functions | |
template<typename... U, size_t... I> | |
Tuple (std::index_sequence< I... > *seq, const Tuple< U... > &src) | |
template<typename... U, size_t... I> | |
Tuple (std::index_sequence< I... > *seq, Tuple< U... > &&src) | |
template<typename... U, size_t... I> | |
void | CopyAssign (std::index_sequence< I... > *, const Tuple< U... > &src) |
template<typename... U, size_t... I> | |
void | MoveAssign (std::index_sequence< I... > *, Tuple< U... > &&src) |
template<size_t... I> | |
Result< void > | CopyFromImpl (std::index_sequence< I... > *, const Tuple &src) |
template<size_t... I> | |
SFINAEHelper< String, T... >::type | ToStringImpl (std::index_sequence< I... > *, const FormatStatement *format) const |
template<typename HASH , size_t... I> | |
HashInt | GetHashCodeImpl (std::index_sequence< I... > *) const |
template<typename HASH , size_t... I> | |
UniqueHash | GetUniqueHashCodeImpl (std::index_sequence< I... > *) const |
template<size_t... I> | |
Bool | EqualsImpl (std::index_sequence< I... > *, const Tuple &other) const |
template<size_t... I> | |
Bool | LessThanImpl (std::index_sequence< I... > *, const Tuple &other) const |
Static Private Attributes | |
static const Bool | COPYABLE |
Additional Inherited Members | |
![]() | |
TupleStorageBase (ENUM_DONT_INITIALIZE) | |
|
private |
|
private |
using Pack = ParameterPack<T...> |
|
default |
Converting copy constructor.
Constructs Tuple<T...> from Tuple<U...> by doing an element-wise copy. Participates in overload resolution only if Ti is constructible from const Ui&.
Converting move constructor.
Constructs Tuple<T...> from Tuple<U...> by doing an element-wise forward. Participates in overload resolution only if Ti is constructible from Ui&&. This also covers the default move constructor.
|
constexpr |
Copy-from-value constructor.
Initializes elements with values.
[in] | x | Values. |
MAXON_IMPLICIT Tuple | ( | U &&... | x | ) |
Forward-and-convert-from-value constructor.
Initializes elements with forwarded values. Participates in overload resolution only if Ti is constructible from Ui&&.
[in] | x | Values. |
|
staticconstexpr |
Converting copy assignment. Does an element-wise copy assignment.
Converting move assignment. Does an element-wise perfect-forwarded assignment.
Result<void> CopyFrom | ( | const typename std::conditional< COPYABLE, DummyParamType, Tuple< T > >::type & | src | ) |
Copies one tuple to another with an element-wise AssignCopy. Use this instead of regular assignment if copying an element may result in an error and is thus not supported with a regular copy assignment.
SFINAEHelper<String, T...>::type ToString | ( | const FormatStatement * | format = nullptr | ) | const |
Returns a formated string representation for this tuple.
HashInt GetHashCode | ( | ) | const |
Returns the hash code generated from the elements of this tuple.
UniqueHash GetUniqueHashCode | ( | ) | const |
Returns the hash value generated from the elements of this tuple.
Returns the element at index I. Equivalent to TupleGet<I>(*this).
Pack::template At<I>::type& Get | ( | ) |
auto Get | ( | ) | const -> const ELEMENTTYPE& |
Returns element with type ELEMENTTYPE. Equivalent to TupleGet<ELEMENTTYPE>(*this).
auto Get | ( | ) | -> ELEMENTTYPE& |
Element-wise comparison for equality.
Returns true, if myElem[i] == src.elem[i] for all i = 0 .. N.
Element-wise less-than from left to right.
Returns true, if myElem[i] < src.elem[i]. Returns false, if myElem[i] > src.elem[i]. Otherwise, if there exist elements at i+1, they are compared by the same rules. Otherwise, returns false.
MAXON_OPERATOR_COMPARISON | ( | Tuple< T > | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |