Namespaces
Variants

std:: tuple_size <std::tuple>

From cppreference.net
Utilities library
헤더에 정의됨 <tuple>
template < class ... Types >

struct tuple_size < std:: tuple < Types... > >

: std:: integral_constant < std:: size_t , sizeof... ( Types ) > { } ;
(C++11부터)

튜플의 요소 개수에 컴파일 타임 상수 표현식으로 접근할 수 있도록 합니다.

목차

헬퍼 변수 템플릿

template < class T >
constexpr std:: size_t tuple_size_v = tuple_size < T > :: value ;
(C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
sizeof...(Types)
(public static member constant)

멤버 함수

operator std::size_t
객체를 std:: size_t 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type std:: size_t
type std:: integral_constant < std:: size_t , value >

예제

#include <iostream>
#include <tuple>
template <class T>
void test(T value)
{
    int a[std::tuple_size_v<T>]; // 컴파일 타임에 사용 가능
    std::cout << std::tuple_size<T>{} << ' ' // 또는 런타임에
              << sizeof a << ' '
              << sizeof value << '\n';
}
int main()
{
    test(std::make_tuple(1, 2, 3.14));
}

가능한 출력:

3 12 16

참고 항목

Structured binding (C++17) 지정된 이름들을 초기화자의 부분 객체나 튜플 요소에 바인딩합니다
(C++11)
튜플과 유사한 타입의 요소 개수를 얻습니다
(클래스 템플릿)
pair 의 크기를 얻습니다
(클래스 템플릿 특수화)
array 의 크기를 얻습니다
(클래스 템플릿 특수화)
std::ranges::subrange 의 크기를 얻습니다
(클래스 템플릿 특수화)
튜플의 지정된 요소에 접근합니다
(함수 템플릿)