ranges_repeat_view

ranges_repeat_view (반복 뷰)

std::ranges::repeat_view은 동일한 값 W를 반복 생성하는 뷰예요. C++23부터 사용할 수 있어요.

출처: cppreference

본문

<ranges> 헤더에 정의되어 있고, 시그니처는 다음과 같아요.

template< std::move_constructible W,
          std::semiregular Bound = std::unreachable_sentinel_t >
    requires (std::is_object_v<W> && std::same_as<W, std::remove_cv_t<W>> &&
             (/*integer-like-with-usable-difference-type*/<Bound> ||
              std::same_as<Bound, std::unreachable_sentinel_t>))
class repeat_view
    : public ranges::view_interface<repeat_view<W, Bound>>

(1) (since C++23)

namespace views {
    inline constexpr /* unspecified */ repeat = /* unspecified */;
}

(2)

    1. 동일한 값 W를 반복 생성하는 뷰. Bound가 unreachable_sentinel이면 무한 뷰예요.
    1. repeat 뷰를 생성하는 뷰 팩토리 객체.

멤버 함수 (Member functions)

  • (constructor) — repeat 뷰 생성 (값과 반복 횟수)
  • begin / end — 반복 요소 반복자/센티널 반환
  • size — 반복 횟수 반환 (경계가 있을 때)

예제 (Example)

이 코드를 실행해 봐요.

#include <ranges>
#include <iostream>

int main()
{
    for (int x : std::views::repeat(7, 3))
        std::cout << x << ' '; // 7 7 7
}

더 알아보기 (Learn more)

cppreference