Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::tuple_cat

      From cppreference.com
      <cpp‎ |utility‎ |tuple
       
       
      Utilities library
       
       
      Defined in header<tuple>
      template<class...Tuples>
      std::tuple</* CTypes */...> tuple_cat( Tuples&&...args);
      (since C++11)
      (until C++14)
      template<class...Tuples>
      constexprstd::tuple</* CTypes */...> tuple_cat( Tuples&&...args);
      (since C++14)
      (until C++23)
      template< tuple-like...Tuples>
      constexprstd::tuple</* CTypes */...> tuple_cat( Tuples&&...args);
      (since C++23)

      Constructs a tuple that is a concatenation of all tuples inargs. The element types/* CTypes */ of the returned tuple is formed by concatenating the elements type packs of allstd::tuple(until C++23)tuple-like(since C++23) types inTuples in order.

      The behavior is undefined if any type instd::decay_t<Tuples>... is not a specialization ofstd::tuple. However, an implementation may choose to support types (such asstd::array andstd::pair) that follow the tuple-like protocol.

      (until C++23)

      The typesstd::decay_t<Tuples>... are constrained to be tuple-like, i.e. each type therein is required to be a specialization ofstd::tuple or another type (such asstd::array andstd::pair) that modelstuple-like.

      (since C++23)

      If any type in/* CTypes */ is not constructible from the type of the corresponding element in the sequence of elements concatenated fromargs,the behavior is undefined(until C++23)the program is ill-formed(since C++23).

      Contents

      [edit]Parameters

      args - zero or more tuples to concatenate

      [edit]Return value

      Astd::tuple object composed of all elements of all argument tuples constructed fromstd::get<j>(std::forward<Ti>(arg)) for each individual element.

      [edit]Example

      Run this code
      #include <iostream>#include <string>#include <tuple> // helper function to print a tuple of any sizetemplate<class Tuple,std::size_t N>struct TuplePrinter{staticvoid print(const Tuple& t){        TuplePrinter<Tuple, N-1>::print(t);std::cout<<", "<< std::get<N-1>(t);}}; template<class Tuple>struct TuplePrinter<Tuple,1>{staticvoid print(const Tuple& t){std::cout<< std::get<0>(t);}}; template<typename...Args,std::enable_if_t<sizeof...(Args)==0,int>=0>void print(conststd::tuple<Args...>& t){std::cout<<"()\n";} template<typename...Args,std::enable_if_t<sizeof...(Args)!=0,int>=0>void print(conststd::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);}

      Output:

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

      [edit]See also

      (C++11)
      creates atuple object of the type defined by the argument types
      (function template)[edit]
      (C++11)
      creates atuple of lvalue references or unpacks a tuple into individual objects
      (function template)[edit]
      creates atuple offorwarding references
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/tuple/tuple_cat&oldid=151757"

      [8]ページ先頭

      ©2009-2025 Movatter.jp