std::make_from_tuple - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::make_from_tuple

From cppreference.com
< cpp‎ | utility

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

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

### [edit] Parameters

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

### [edit] Return value

The constructed `T` object.

### [edit] Notes

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.

### [edit] 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),
            std::make_index_sequence<std::tuple_size_v<std::decay_t<Tuple>>>{});
    }

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

make_tuple | creates a `tuple` object of the type defined by the argument types (function template) [edit]
forward_as_tuple | creates a `tuple` of rvalue references (function template) [edit]
apply (C++17) | calls a function with a tuple of arguments (function template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/make_from_tuple&oldid=92145"
Category:

- Todo no example