名前空間
変種
操作

std::tuple_cat

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

Defined in header <tuple>
template< class... Tuples >
tuple<CTypes...> tuple_cat(Tuples&&... args);
(C++11およびそれ以降)
args内のすべてのタプルを連結したものであるタプルを構築し.
Original:
Constructs a tuple that is a concatenation of all tuples in args.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] パラメータ

args -
連結するゼロ以上のタプル
Original:
zero or more tuples to concatenate
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

個々の要素のstd::tupleから構築すべての引数のタプルのすべての要素で構成さstd::get<i>(std::forward<Ti>(arg))オブジェクト.
Original:
A std::tuple object composed of all elements of all argument tuples constructed from std::get<i>(std::forward<Ti>(arg)) for each individual element.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

#include <iostream>
#include <tuple>
#include <string>
 
// helper function to print a tuple of any size
template<class Tuple, std::size_t N>
struct TuplePrinter {
    static void print(const Tuple& t) 
    {
        TuplePrinter<Tuple, N-1>::print(t);
        std::cout << ", " << std::get<N-1>(t);
    }
};
 
template<class Tuple>
struct TuplePrinter<Tuple, 1> {
    static void print(const Tuple& t) 
    {
        std::cout << std::get<0>(t);
    }
};
 
template<class... Args>
void print(const std::tuple<Args...>& t) 
{
    std::cout << "(";
    TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
    std::cout << ")\n";
}
// end helper function
 
int main()
{
    std::tuple<int, std::string, float> t1(10, "Test", 3.14);
    int n = 7;
    auto t2 = std::tuple_cat(t1, std::make_pair("Foo", "bar"), t1, std::tie(n));
    n = 10;
    print(t2);
}

出力:

(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 10)
引数の型で定義されるtuple型のオブジェクトを作成します
(関数テンプレート) [edit]
左辺値参照のtupleを作成します。tupleを個々のオブジェクトに分解することにも応用できます。
(関数テンプレート) [edit]
右辺値参照を内包するtupleを作成します。
(関数テンプレート) [edit]