make_from_tuple
はヘッダーファイル<tuple>
で定義されている。
template <class T, class Tuple>
constexpr T make_from_tuple(Tuple&& t);
apply
はtuple
の要素を実引数に関数を呼び出すライブラリだが、make_from_tuple
はtuple
の要素を実引数にコンストラクターを呼び出すライブラリだ。
ある型T
と要素数N
のtuple t
に対して、make_from_tuple<T>(t)
は、T
型をT( get<0>(t), get<1>(t), ... , get<N-1>(t) )
のように構築して、構築したT
型のオブジェクトを返す。
class X
{
template < typename ... Types >
T( Types ... ) { }
} ;
int main()
{
// int, int, int
std::tuple t1(1,2,3) ;
// X(1,2,3)
X x1 = std::make_from_tuple<X>( t1 )
// int, double, const char *
std::tuple t2( 123, 4.56, "hello" ) ;
// X(123, 4.56, "hello")
X x2 = std::make_from_tuple<X>( t2 ) ;
}