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.
t | - | tuple whose elements to be used as arguments to the constructor of T |
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.
#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)); }
Output:
creates a tuple object of the type defined by the argument types (function template) |
|
creates a tuple of rvalue references (function template) |
|
(C++17) | calls a function with a tuple of arguments (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/make_from_tuple