std::make_from_tuple

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

# 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

DRApplied toBehavior as publishedCorrect behavior
LWG 3528C++17cast containing reinterpret_cast etc. was allowed in the case of 1-tupleprohibited

# See also