std::move_sentinel

std::move_sentinel (이동 센티널 어댑터)

std::move_iterator와 함께 범위를 나타내는 데 쓰이는 센티널 어댑터예요. C++20부터 있어요.

출처: cppreference

본문

<iterator> 헤더에 정의돼 있어요.

template< std::semiregular S >
class move_sentinel;

std::move_sentinelstd::move_iterator와 함께 범위를 나타내는 데 쓰이는 센티널 어댑터예요.

템플릿 매개변수

  • S — 기본 센티널의 타입.

멤버 함수

  • (constructor) — 새 move_sentinel을 생성해요.
  • operator= — 한 move_sentinel의 내용을 다른 것에 할당해요.
  • base — 기본 센티널의 사본을 돌려줘요.

멤버 객체

  • last (private, exposition-only) — 기본 센티널.

비멤버 함수

  • operator== (C++20) — 기본 반복자와 기본 센티널을 비교해요.
  • operator- (C++20) — 기본 반복자와 기본 센티널 사이의 거리를 계산해요.

예제

#include <iterator>
#include <algorithm>
#include <vector>
#include <iostream>

int main()
{
    std::vector<int> v{1, 2, 3};
    std::move_iterator<std::vector<int>::iterator> it(v.begin());
    std::move_sentinel<std::vector<int>::iterator> s(v.end());
    // it 와 s 로 범위를 나타냄
    for (; it != s; ++it)
        std::cout << *it << ' '; // "1 2 3 "
}

더 알아보기 (Learn more)

cppreference