Namespaces
Variants

std::ranges::iota_view<W, Bound>:: iota_view

From cppreference.net
Ranges library
Range adaptors
iota_view ( ) requires std:: default_initializable < W > = default ;
(1) (C++20 이후)
constexpr explicit iota_view ( W value ) ;
(2) (C++20 이후)
constexpr explicit iota_view ( std:: type_identity_t < W > value,
std:: type_identity_t < Bound > bound ) ;
(3) (C++20 이후)
constexpr explicit iota_view ( /*iterator*/ first, /* see below */ last ) ;
(4) (C++20 이후)

iota_view 를 생성합니다.

오버로드 데이터 멤버
value_ bound_
(1) 값 초기화 값 초기화
(2) value 로 초기화됨
(3) bound 로 초기화됨
(4) first. value_ 로 초기화됨 아래 참조
2,3) 다음 조건 중 어느 하나를 만족할 경우, 동작은 정의되지 않음:
4) 다음 조건 중 하나라도 만족되면, 동작은 정의되지 않음:
last 의 타입과 bound_ 초기화 방법은 Bound 타입이 나타내는 것에 따라 결정됩니다:
Bound 타입이 나타내는 것 last 의 타입 bound_
W iterator last. value_ 로 초기화됨
std::unreachable_sentinel_t Bound last 로 초기화됨
다른 모든 타입 sentinel last. bound_ 로 초기화됨

매개변수

value - 시작 값
bound - 경계 값
first - 시작 값을 나타내는 반복자
last - 경계를 나타내는 반복자 또는 센티넬

예제

#include <cassert>
#include <iostream>
#include <iterator>
#include <ranges>
int main()
{
    const auto l = {1, 2, 3, 4};
    auto i1 = std::ranges::iota_view<int, int>(); // 오버로드 (1)
    assert(i1.empty() and i1.size() == 0);
    auto i2 = std::ranges::iota_view(1); // 오버로드 (2)
    assert(not i2.empty() and i2.front() == 1);
    for (std::cout << "1) "; auto e : i2 | std::views::take(3))
        std::cout << e << ' ';
    std::cout << '\n';
    auto i3 = std::ranges::iota_view(std::begin(l)); // 오버로드 (2)
    assert(not i3.empty() and i3.front() == l.begin());
    for (std::cout << "2) "; auto e : i3 | std::views::take(4))
        std::cout << *e << ' ';
    std::cout << '\n';
    auto i4 = std::ranges::iota_view(1, 8); // 오버로드 (3)
    assert(not i4.empty() and i4.front() == 1 and i4.back() == 7);
    for (std::cout << "3) "; auto e : i4)
        std::cout << e << ' ';
    std::cout << '\n';
    auto i5 = std::ranges::iota_view(l.begin(), l.end()); // 오버로드 (4)
    for (std::cout << "4) "; auto e : i5)
        std::cout << *e << ' ';
    std::cout << '\n';
    auto i6 = std::ranges::iota_view(l.begin(), std::unreachable_sentinel); // (4)
    for (std::cout << "5) "; auto e : i6 | std::views::take(3))
        std::cout << *e << ' ';
    std::cout << '\n';
}

출력:

1) 1 2 3
2) 1 2 3 4
3) 1 2 3 4 5 6 7
4) 1 2 3 4
5) 1 2 3

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 3523 C++20 오버로드 (4) 가 잘못된 sentinel 타입을 사용할 수 있음 수정됨
P2711R1 C++20 오버로드 (3,4) 가 explicit가 아니었음 explicit로 변경됨