std:: tuple_size <std::pair>
|
헤더에 정의됨
<utility>
|
||
|
template
<
class
T1,
class
T2
>
struct
tuple_size
<
std::
pair
<
T1, T2
>>
|
(C++11부터) | |
페어에 대한 std:: tuple_size 부분 특수화는 튜플과 유사한 구문을 사용하여 페어의 요소 개수(항상 2)를 컴파일 타임에 얻을 수 있는 방법을 제공합니다.
목차 |
std:: integral_constant 에서 상속됨
멤버 상수
|
value
[static]
|
상수 값 2
(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> #include <utility> template<class T> void test([[maybe_unused]]T t) { [[maybe_unused]] int a[std::tuple_size<T>::value]; // 컴파일 타임에 사용 가능 std::cout << std::tuple_size<T>::value << '\n'; // 또는 런타임에 사용 } int main() { test(std::make_tuple(1, 2, 3.14)); test(std::make_pair(1, 3.14)); }
출력:
3 2
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2313 | C++11 |
pair
에 대한 특수화가
integral_constant
에서 파생될 것을 요구하지 않았음
|
요구됨 |
참고 항목
| Structured binding (C++17) | 지정된 이름들을 초기화자의 부분 객체나 튜플 요소에 바인딩합니다 |
|
(C++11)
|
튜플과 유사한 타입의 요소 개수를 얻습니다
(class template) |
|
(C++11)
|
array
의 크기를 얻습니다
(class template specialization) |
|
(C++11)
|
|
|
std::ranges::subrange
의 크기를 얻습니다
(class template specialization) |
|
|
(C++11)
|
pair
의 요소 타입을 얻습니다
(class template specialization) |