名前空間
変種
操作

std::tuple_cat

提供: cppreference.com
< cpp‎ | utility‎ | tuple
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
std::tuple
メンバ関数
非メンバ関数
tuple_cat
(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20未満)(C++20)
推定ガイド(C++17)
ヘルパークラス
 
ヘッダ <tuple> で定義
template< class... Tuples >
std::tuple<CTypes...> tuple_cat(Tuples&&... args);
(C++11以上)
(C++14以上ではconstexpr)

args 内のすべてのタプルを連結したタプルを��築します。

std::decay_t<Tuples>... 内のいずれかの型が std::tuple の特殊化でない場合、動作は未定義です。 ただし、処理系はタプルライクな規約に従う型 (std::arraystd::pair など) をサポートしても構いません。

目次

[編集] 引数

args - 連結する0個以上のタプル

[編集] 戻り値

個々の要素に対して std::get<i>(std::forward<Ti>(arg)) から構築された、すべての引数タプルの全ての要素から構成される std::tuple オブジェクト。

[編集]

#include <iostream>
#include <tuple>
#include <string>
 
// 任意のサイズのタプルを表示するためのヘルパー関数
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";
}
// ヘルパー関数おわり
 
int main()
{
    std::tuple<int, std::string, float> t1(10, "Test", 3.14);
    int n = 7;
    auto t2 = std::tuple_cat(t1, std::make_tuple("Foo", "bar"), t1, std::tie(n));
    n = 10;
    print(t2);
}

出力:

(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 10)

[編集] 関連項目

引数の型によって定義される型の tuple オブジェクトを作成します
(関数テンプレート) [edit]
左辺値参照の tuple を作成したり、タプルを個々のオブジェクトに分解したりします
(関数テンプレート) [edit]
転送参照tuple を作成します
(関数テンプレート) [edit]