std::make_from_tuple
Min standard notice:
Header: <tuple>
Construct an object of type T, using the elements of the tuple t as the arguments to the constructor.
# Declarations
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)
# Parameters
t: tuple whose elements to be used as arguments to the constructor of T
# Return value
The constructed T object or reference.
# 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.
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 tuple-like.
Due to guaranteed copy elision, T need not be movable.
# Example
#include <iostream>
#include <tuple>
struct Foo
{
Foo(int first, float second, int third)
{
std::cout << first << ", " << second << ", " << third << '\n';
}
};
int main()
{
auto tuple = std::make_tuple(42, 3.14f, 0);
std::make_from_tuple<Foo>(std::move(tuple));
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3528 | C++17 | cast containing reinterpret_cast etc. was allowed in the case of 1-tuple | prohibited |