-
首页
-
C4D R23.110 C++ SDK
Tuple< T > Class Template Reference
#include <tuple.h>
详细描述
template<typename... T>
class maxon::Tuple< T >
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:
Tuple<T1, T2, T3> t;
// ... same size and layout as ...
struct
MyType { T1 a; T2 b; T3 c; };
MyType t;
Tuples allow to create generic classes which store a variable number of member-like types that can be initialized from a parameter pack. Example:
template
<
typename
... Ts>
class
MyGenericClass
{
Tuple
<Ts ...> storedArgs;
// Similar to T1 m1; T2 m2; ... TN mN
MyGenericClass(Ts ... args) : storedArgs(args) { }
// Similar to m1(a1), m2(a2), ... mN(aN)
};
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:
A a; B b; C c;
Tie
(a, b, c) = FuncThatReturnsTupleOfABC();
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.
-
Template Parameters
-
公共成员函数
|
|
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
)
|
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
|
HashInt
|
GetHashCode
() const
|
template<typename HASH >
|
HashInt
|
GetHashCode
() 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
)
|
私有成员函数
|
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<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
|
Member Typedef Documentation
◆
Super
◆
IndexSequence
◆
Pack
构造函数 & 析构函数文档编制
◆
Tuple()
[1/7]
◆
Tuple()
[2/7]
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&.
◆
Tuple()
[3/7]
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.
◆
Tuple()
[4/7]
Copy-from-value constructor.
Initializes elements with values.
-
参数
-
◆
Tuple()
[5/7]
Forward-and-convert-from-value constructor.
Initializes elements with forwarded values. Participates in overload resolution only if Ti is constructible from Ui&&.
-
参数
-
◆
Tuple()
[6/7]
Tuple
|
(
|
std::index_sequence< I... > *
|
seq
,
|
|
|
const
Tuple
< U... > &
|
src
|
|
)
|
|
|
|
private
|
◆
Tuple()
[7/7]
Tuple
|
(
|
std::index_sequence< I... > *
|
seq
,
|
|
|
Tuple
< U... > &&
|
src
|
|
)
|
|
|
|
private
|
成员函数文档编制
◆
operator=()
[1/2]
Converting copy assignment. Does an element-wise copy assignment.
◆
operator=()
[2/2]
Converting move assignment. Does an element-wise perfect-forwarded assignment.
◆
CopyFrom()
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.
◆
ToString()
Returns a formated string representation for this tuple.
◆
GetHashCode()
[1/2]
Returns the hash code generated from the elements of this tuple.
◆
GetHashCode()
[2/2]
Returns the hash code generated from the elements of this tuple.
◆
Get()
[1/4]
std::add_const<typename Pack::template At<I>::type>::type& Get
|
(
|
|
)
|
const
|
Returns the element at index I. Equivalent to TupleGet<I>(*this).
◆
Get()
[2/4]
Pack::template At<I>::type& Get
|
(
|
|
)
|
|
◆
Get()
[3/4]
auto Get
|
(
|
|
)
|
const -> const ELEMENTTYPE&
|
Returns element with type ELEMENTTYPE. Equivalent to TupleGet<ELEMENTTYPE>(*this).
◆
Get()
[4/4]
auto Get
|
(
|
|
)
|
-> ELEMENTTYPE&
|
◆
operator==()
Bool
operator==
|
(
|
const
Tuple
< T > &
|
other
|
)
|
const
|
Element-wise comparison for equality.
Returns true, if myElem[i] == src.elem[i] for all i = 0 .. N.
◆
operator<()
Bool
operator<
|
(
|
const
Tuple
< T > &
|
other
|
)
|
const
|
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()
MAXON_OPERATOR_COMPARISON
|
(
|
Tuple
< T >
|
|
)
|
|
◆
CopyAssign()
void CopyAssign
|
(
|
std::index_sequence< I... > *
|
,
|
|
|
const
Tuple
< U... > &
|
src
|
|
)
|
|
|
|
private
|
◆
MoveAssign()
void MoveAssign
|
(
|
std::index_sequence< I... > *
|
,
|
|
|
Tuple
< U... > &&
|
src
|
|
)
|
|
|
|
private
|
◆
CopyFromImpl()
Result
<void> CopyFromImpl
|
(
|
std::index_sequence< I... > *
|
,
|
|
|
const
Tuple
< T > &
|
src
|
|
)
|
|
|
|
private
|
◆
ToStringImpl()
◆
GetHashCodeImpl()
HashInt
GetHashCodeImpl
|
(
|
std::index_sequence< I... > *
|
|
)
|
const
|
|
private
|
◆
EqualsImpl()
Bool
EqualsImpl
|
(
|
std::index_sequence< I... > *
|
,
|
|
|
const
Tuple
< T > &
|
other
|
|
)
|
|
const
|
|
private
|
◆
LessThanImpl()
Bool
LessThanImpl
|
(
|
std::index_sequence< I... > *
|
,
|
|
|
const
Tuple
< T > &
|
other
|
|
)
|
|
const
|
|
private
|
Member Data Documentation
◆
COPYABLE
auto Tie(TYPES &... args) -> Tuple< TYPES &... >
定义:
tuple.h:1176