std::ranges::subrange<I,S,K>:: size
From cppreference.net
C++
Ranges library
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | |||||||||||||||||||
|
|||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
std::ranges::subrange
|
constexpr
/*make-unsigned-like-t*/
<
std::
iter_difference_t
<
I
>>
size
(
)
const
requires ( K == ranges :: subrange_kind :: sized ) ; |
(C++20 이후) | |
subrange
내의 요소 개수를 얻습니다:
-
StoreSize가 true 이면size_를 반환합니다. -
그렇지 않으면
to-unsigned-like (end_-begin_ ) 를 반환합니다.
/*make-unsigned-like-t*/
의 정의에 대해서는
make-unsigned-like-t
를 참조하십시오.
반환값
위에서 설명한 바와 같습니다.
예제
이 코드 실행
#include <functional> #include <iostream> #include <ranges> #include <utility> int main() { const auto v = {2, 2, 2, 7, 1, 1, 1, 1, 8, 2, 2, 2, 2, 2}; // views::chunk_by의 값 타입은 ranges::subrange입니다 auto to_pair = [](auto sub) { return std::make_pair(sub[0], sub.size()); }; /* ^^^^ */ auto pairs = v | std::views::chunk_by(std::equal_to{}) | std::views::transform(to_pair); for (auto x : pairs bitor std::views::keys) std::cout << x << ' '; std::cout << '\n'; for (auto x : pairs bitor std::views::values) std::cout << x << ' '; std::cout << '\n'; }
출력:
2 7 1 8 2 3 1 4 1 5
참고 항목
subrange
가 비어 있는지 확인
(public member function) |
|
|
(C++17)
(C++20)
|
컨테이너나 배열의 크기를 반환
(function template) |
|
(C++20)
|
범위의 크기와 같은 정수를 반환
(customization point object) |