std:: tuple_size <std:ranges::subrange>
|
헤더에 정의됨
<ranges>
|
||
|
template
<
class
I,
class
S,
ranges::
subrange_kind
K
>
struct
tuple_size
<
ranges::
subrange
<
I, S, K
>>
|
(C++20 이후) | |
std::tuple_size
의 부분 특수화는
std::ranges::subrange
에 대해 튜플과 유사한 구문을 사용하여
subrange
의 구성 요소 개수(항상 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 <array> #include <iostream> #include <iterator> #include <ranges> int main() { static_assert(2 == std::tuple_size_v<std::ranges::subrange<int*, int*>>); using array5 = std::array<int, 5>; static_assert(2 == std::tuple_size<std::ranges::subrange< array5::const_iterator, array5::const_iterator>>{}); constexpr array5 a{1, 2, 3, 4, 5}; std::ranges::subrange sub_a1{a}; for (std::cout << "sub_a1: { "; int e : sub_a1) std::cout << e << ' '; std::cout << "}\n"; std::ranges::subrange sub_a2{std::next(cbegin(a)), std::prev(cend(a))}; const auto [first, last] = sub_a2; std::cout << "sub_a2 size = " << std::distance(first, last) << '\n'; for (std::cout << "sub_a2: { "; int e : sub_a2) std::cout << e << ' '; std::cout << "}\n"; }
출력:
sub_a1: { 1 2 3 4 5 }
sub_a2 size = 3
sub_a2: { 2 3 4 }
참고 항목
| Structured binding (C++17) | 지정된 이름들을 초기화자의 부분 객체나 튜플 요소에 바인딩합니다 |
|
(C++11)
|
튜플과 유사한 타입의 요소 개수를 구합니다
(클래스 템플릿) |
|
(C++11)
|
tuple
의 크기를 구합니다
|
|
(C++11)
|
pair
의 크기를 구합니다
(클래스 템플릿 특수화) |
|
(C++11)
|
array
의 크기를 구합니다
(클래스 템플릿 특수화) |
|
std::ranges::subrange
의 반복자나 센티널 타입을 구합니다
(클래스 템플릿 특수화) |