Constructor constructor
The constructor of a tuple is ordinary, nothing to say.
Default (1) |
constexpr tuple (); default constructor |
Copy/move (2) |
Tuple (const tuple& TPL) = default; Copy constructor tuple (tuple&& TPL) = default; Move constructor |
Implicit conversion (3) |
Template <class ... utypes> Tuple (const tuple<utypes...>& TPL); Generalized copy constructors, as long as the corresponding parameters can be converted by default template <class ... utypes> tuple (tuple<utypes...>&& TPL); generalized move constructor, as long as the corresponding parameter can be converted by default |
Initialization (4) |
Explicit tuple (const types& ... elems); construct and initialize template <class ... Utypes> Explicit tuple (utypes&& ... elems); construct and initialize, parameter type only requires the ability to convert by default |
Conversion from pair (5) |
Template <class U1, class u2> tuple (const pair<u1,u2>& PR); From pair construction template <class U1, class u2> tuple (pair<u1,u2>&& PR); |
Allocator (6) |
To increase the allocator parameters on the basis of the above 5 classes, the first parameter has no practical meaning and is used only to distinguish it from (3). Template<class alloc> tuple (allocator_arg_t aa, const alloc& Alloc); Template<class alloc> tuple (alloca tor_arg_t AA, const alloc& Alloc, const tuple& TPL); Template<class alloc> tuple (allocator_arg_t AA, const alloc& Alloc, tuple&& TPL); Template<class Alloc,class ... Utypes> tuple (allocator_arg_t aa, const alloc& Alloc, const tuple<utypes...>& TPL); Template<class A Lloc, class ... Utypes> tuple (allocator_arg_t aa, const alloc& Alloc, tuple<utypes...>&& TPL); template<class Alloc> tuple (allocator_arg_t aa, const alloc& Alloc, const types& .... elems); Template<class Alloc, class. . Utypes> tuple (allocator_arg_t aa, const alloc& Alloc, Utypes&& .... elems); Template<class Alloc, Class U 1, class u2> tuple (allocator_arg_t aa, const alloc& Alloc, const pair<u1,u2>& PR); Template<class all OC, Class U1, class u2> tuple (allocator_arg_t AA, const Alloc& alloc, pair<u1,u2>&& PR); |
Get the component of a tuple
The Get template function can get a reference to a tuple component, as declared, a constant tuple gets a constant reference, an rvalue reference tuple gets an rvalue reference, and a non-rvalue reference obtains a reference.
(1) |
Template <size_t I, class ... Types>typename tuple_element< I, tuple<types...> >::type& get (tuple<types...>& TPL) Noexcept |
(2) |
Template <size_t I, class ... Types>typename tuple_element< I, tuple<types...> >::type&& get (tuple<types...>& & TPL) noexcept; |
(3) |
Template <size_t I, class ... Types>typename tuple_element< I, tuple<types...> >::type const& get (const tuple<Types...> & TPL) noexcept; |
Std::make_tuple
Template<class ... Types> tuple<vtypes...> make_tuple (types&& .... args);
Make_tuple a template function that generates a tuple based on the argument type and initializes it with the value of the argument. When the compiler infers the type of a tuple component, it strips out the top-level const property of the argument, the reference property (including the Rvalue reference), which means that the created tuple is stored as a value. The array is inferred as a pointer, and the function is inferred as a function pointer. If you need to infer a reference type, use Std::ref or std::cref.
Std::tie
Template<class ... Types> constexpr tuple<types&...> tie (types& .... args) noexcept;
The tie generates a tuple, which contains the components that are all references to the arguments, in the exact opposite of Make_tuple. Used primarily to extract data from a tuple. For example:
int a,b,c;
Auto x = make_tuple (n/a);
Std::tie (A,B,C) = x;
Std::forward_as_tuple
Template<class ... Types>
constexpr tuple<types&&...> forward_as_tuple (types&& ...) Noexcept
As with Std::tie, a tuple is generated that is all referenced, but Std::tie accepts only lvalue, and Std::forward_as_tuple Lvalue and Rvalue are accepted. is primarily used for forwarding data that does not lose the type attribute.
Std::tuple_cat
Template<class ... Tuples>
Tuple<ctypes...> Tuple_cat (tuples&& tlps);
This function takes more than one tuple as a parameter, and then returns a tuple. The tuple returned tuple_cat all elements of a tuple in the argument to a new tuple in the order of the tuple in the parameter and its order in the tuple. The type of the element in the new tuple is exactly the same as the type of the element in the tuple in the parameter.
Template<class ... Types>struct tuple_size<tuple<types...>>;
Tuple_size is an auxiliary class used to get the number of elements in a tuple. Usage: tuple_size<decltype (tuple) >::value
template<size_t I,class ... Types>struct Tuple_element<i,tuple<types ...>>;
Tuple_element is an auxiliary class used to get the type of an element in a tuple. Usage: tuple_size<1,decltype (tuple) >::type
A tuple of the C + + standard library