Namespaces
Variants

std:: tuple_cat

From cppreference.net
Utilities library
헤더 파일에 정의됨 <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 */ 은 모든 std::tuple (C++23 이전) tuple-like (C++23 이후) 타입들의 요소 타입 팩들을 순서대로 연결하여 형성됩니다.

std:: decay_t < Tuples > ... 내의 어떤 타입이 std::tuple 의 특수화가 아닌 경우, 동작은 정의되지 않는다. 그러나 구현체는 튜플-유사 프로토콜을 따르는 타입들(예: std::array std::pair )을 지원하도록 선택할 수 있다.

(C++23 이전)

std:: decay_t < Tuples > ... 타입들은 튜플-유사(tuple-like)로 제한된다. 즉, 그 안의 각 타입은 std::tuple 의 특수화이거나 tuple-like 를 모델링하는 다른 타입(예: std::array std::pair )이어야 한다.

(C++23 이후)

/* CTypes */ 내의 어떤 타입이 args 에서 연결된 요소들의 시퀀스에 있는 해당 요소의 타입으로부터 생성 가능하지 않다면, 동작은 정의되지 않음 (C++23 이전) 프로그램의 형식이 잘못됨 (C++23 이후) .

목차

매개변수

args - 연결할 0개 이상의 튜플

반환값

모든 인자 튜플들의 모든 요소들로 구성된 std::tuple 객체는 각 개별 요소에 대해 std :: get < j > ( std:: forward < Ti > ( arg ) ) 로부터 생성됩니다.

예제

#include <iostream>
#include <string>
#include <tuple>
// 임의 크기의 튜플을 출력하는 헬퍼 함수
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";
}
// 헬퍼 함수 끝
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)
lvalue 참조들의 tuple 을 생성하거나 튜플을 개별 객체들로 풀어냄
(함수 템플릿)
전달 참조 들의 tuple 을 생성함
(함수 템플릿)