名前空間
変種
操作

std::make_tuple

提供: cppreference.com
< cpp‎ | utility‎ | tuple

Defined in header <tuple>
template< class... Types >
tuple<VTypes...> make_tuple( Types&&... args );
(C++11およびそれ以降)

Creates a tuple object, deducing the target type from the types of arguments. The deduced types are std::decay<Ti>::type (transformed as if passed to a function by value) unless application of std::decay results in std::reference_wrapper<X> for some type X, in which case the deduced type is is X&.

[編集] パラメータ

args -
からタプルを構築するためにゼロ個以上の引数
Original:
zero or more arguments to construct the tuple from
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

A std::tuple object containing the given values.

[編集]

#include <iostream>
#include <tuple>
#include <functional>
 
int main()
{
    auto t1 = std::make_tuple(10, "Test", 3.14);
    std::cout << "The value of t1 is "
              << "(" << std::get<0>(t1) << ", " << std::get<1>(t1)
              << ", " << std::get<2>(t1) << ")\n";
 
    int n = 1;
    auto t2 = std::make_tuple(std::ref(n), n);
    n = 7;
    std::cout << "The value of t2 is "
              << "(" << std::get<0>(t2) << ", " << std::get<1>(t2) << ")\n";
}

出力:

The value of t1 is (10, Test, 3.14)
The value of t2 is (7, 1)
左辺値参照のtupleを作成します。tupleを個々のオブジェクトに分解することにも応用できます。
(関数テンプレート) [edit]
右辺値参照を内包するtupleを作成します。
(関数テンプレート) [edit]
任意の数のタプルを連結して新たなtupleを作成します。
(関数テンプレート) [edit]