Namespaces
Variants
Actions

std::make_from_tuple

From cppreference.com
< cpp‎ | utility
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)  
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
make_from_tuple
(C++17)
(C++23)


 
Defined in header <tuple>
template< class T, class Tuple >
constexpr T make_from_tuple( Tuple&& t );
(since C++17)
(until C++23)
template< class T, tuple-like Tuple >
constexpr T make_from_tuple( Tuple&& t );
(since C++23)

Construct an object of type T, using the elements of the tuple t as the arguments to the constructor.

Given the exposition-only function /*make-from-tuple-impl*/ defined as follows:
template<class T, tuple-like Tuple, std::size_t... I> // no constraint on Tuple before C++23
constexpr T /*make-from-tuple-impl*/(Tuple&& t, std::index_sequence<I...>)
{
    return T(std::get<I>(std::forward<Tuple>(t))...);
}

The effect is equivalent to:
return /*make-from-tuple-impl*/<T>(
    std::forward<Tuple>(t),
    std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<Tuple>>>{}
);
.

If

(since C++23)

the program is ill-formed.

Contents

[edit] Parameters

t - tuple whose elements to be used as arguments to the constructor of T

[edit] Return value

The constructed T object or reference.

[edit] Notes

Tuple need not be std::tuple, and instead may be anything that supports std::get and std::tuple_size; in particular, std::array and std::pair may be used.

(until C++23)

Tuple is constrained to be tuple-like, i.e. each type therein is required to be a specialization of std::tuple or another type (such as std::array and std::pair) that models