tuple元组(C++11及以后,如C++14)
类tuple与array最本质的区别当数tuple元组元素类型可以不一样,而统一数组array的元素类型必须一样。
本文主要举例:
tuple_size
Example
|
|
Output:
foo contains: 100 y |
tie----(unpack)
Example
|
|
Output:
myint contains: 10 mychar contains: a |
std:tuple_element
Member types
member type | definition |
---|---|
type | The Ith type in the tuple object |
Example
|
|
Output:
mytuple contains: 10 and a |
tuple_size
Member constants
member constant | definition |
---|---|
value | The number of elements in the tuple or tuple-like object. This is a constexpr value of the unsigned integral type size_t. |
Example
|
|
Output:
mytuple has 3 elements |
forward_as_tuple
Parameters
- args
- List of elements to be forwarded as a tuple object of references.
Return Value
A tuple object with rvalue references to args suitable to be forwarded as argument to a function.
Example
|
|
Output:
John Smith, 25 John Daniels, 22 |
tuple_cat
Parameters
- tpls
- Comma-separated list of tuple objects. These may be of different types.
Return Value
A tuple object of the appropriate type to hold args.
The type of the returned object (tuple<CTypes...>
) is the tuple type that contains the ordered sequence of all the extended types inTuples.
Example
|
|
Output:
myauto contains: 3.14 pi 10 a |
ignore tie
Parameters
- args
- List of objects (lvalues) to be tied as elements of a tuple.
Return Value
A tuple with lvalue references to args.
Example
|
|
Output:
myint contains: 10 mychar contains: a |