std::tuple_cat
From cppreference.com
| ヘッダ <tuple> で定義 |
||
template< class... Tuples > std::tuple</* CTypes */...> tuple_cat( Tuples&&... args ); |
(C++11以降) (C++14まで) |
|
| template< class... Tuples > constexpr std::tuple</* CTypes */...> tuple_cat( Tuples&&... args ); |
(C++14以降) (C++23まで) |
|
| template< tuple-like... Tuples > constexpr std::tuple</* CTypes */...> tuple_cat( Tuples&&... args ); |
(C++23から) | |
args 内のすべてのタプルを連結したタプルを構築します。返されるタプルの要素型 /* CTypes */ は、Tuples 内のすべてのタプルの要素型パックを順に連結して形成されます。(C++23 まで)(until C++23)(C++23 以降)(since C++23)
|
std::decay_t<Tuples>... のいずれかの型が std::tuple の特殊化でない場合、動作は未定義です。ただし、実装によっては、タプルライクプロトコルに従う型(std::array や std::pair など)をサポートすることを選択する場合があります。 |
(C++23まで) |
|
std::decay_t<Tuples>... の型はタプルライクであるように制約されており、つまり、各型は std::tuple の特殊化、またはタプルライク |
(C++23から) |
/* CTypes */ のいずれかの型が、args から連結された要素のシーケンスの対応する要素の型から構築できない場合、動作は未定義です(until C++23)プログラムは不適格となります(since C++23)。
目次 |
[編集] パラメータ
| args | - | 連結するゼロ個以上のタプル |
[編集] 戻り値
個々の要素について std::decay_t<Ti> 型の引数 arg に対して std::forward<Ti>(arg) から std::get<j> で取得した要素で構成される std::tuple オブジェクト。
[編集] 例
このコードを実行
#include <iostream> #include <string> #include <tuple> // 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<typename... Args, std::enable_if_t<sizeof...(Args) == 0, int> = 0> void print(const std::tuple<Args...>& t) { std::cout << "()\n"; } template<typename... Args, std::enable_if_t<sizeof...(Args) != 0, int> = 0> 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_tuple("Foo", "bar"), t1, std::tie(n)); n = 42; print(t2); }
出力
(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 42)
[編集] 関連項目
| (C++11) |
引数型によって定義された型の tuple オブジェクトを生成する(関数テンプレート) |
| (C++11) |
左辺値参照のtupleを生成するか、タプルを個別のオブジェクトにアンパックする (関数テンプレート) |
| (C++11) |
転送参照の tuple を生成する(関数テンプレート) |