std::make_from_tuple (3) - Linux Manuals

std::make_from_tuple: std::make_from_tuple


std::make_from_tuple - std::make_from_tuple


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

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


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

Return value

The constructed T object.


The 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.
Due to guaranteed_copy_elision, T need not be movable.

Possible implementation

  namespace detail {
  template <class T, class Tuple, std::size_t... I>
  constexpr T make_from_tuple_impl( Tuple&& t, std::index_sequence<I...> )
    return T(std::get<I>(std::forward<Tuple>(t))...);
  } // namespace detail

  template <class T, class Tuple>
  constexpr T make_from_tuple( Tuple&& t )
      return detail::make_from_tuple_impl<T>(std::forward<Tuple>(t),


// Run this code

  #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);


  42, 3.14, 0

See also

                 creates a tuple object of the type defined by the argument types
make_tuple (function template)
                 creates a tuple of rvalue references
forward_as_tuple (function template)

apply calls a function with a tuple of arguments
                 (function template)