Namespaces
Variants

std::ranges:: views:: repeat, std::ranges:: repeat_view

From cppreference.net
Ranges library
Range adaptors
헤더에 정의됨 <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) (C++23부터)
namespace views {

inline constexpr /* 지정되지 않음 */ repeat = /* 지정되지 않음 */ ;

}
(2) (C++23부터)
호출 시그니처
template < class W >

requires /* 아래 참조 */

constexpr /* 아래 참조 */ repeat ( W && value ) ;
(C++23부터)
template < class W, class Bound >

requires /* 아래 참조 */

constexpr /* 아래 참조 */ repeat ( W && value, Bound && bound ) ;
(C++23부터)
헬퍼 개념
concept /*integer-like-with-usable-difference-type*/ =

/*is-signed-integer-like*/ < T > ||

( /*is-integer-like*/ < T > && std:: weakly_incrementable < T > )
(3) ( 설명 전용* )
1) 동일한 값을 반복적으로 생성하여 요소 시퀀스를 만들어내는 범위 팩토리. 유한(bounded) 또는 무한(unbounded)일 수 있습니다.
2) views :: repeat ( e ) views :: repeat ( e, f ) 표현식 동등 합니다 repeat_view < std:: decay_t < decltype ( ( E ) ) >> ( e ) repeat_view ( e, f ) 에 각각 해당하며, 이는 모든 적합한 부분표현식 e f 에 대해 적용됩니다.
3) 타입이 integer-like 인지 여부와 사용 가능한 difference type 을 가지고 있는지 판단합니다.

repeat_view random_access_range 를 모델링합니다. 만약 Bound std::unreachable_sentinel_t 가 아니라면, repeat_view 는 또한 sized_range common_range 를 모델링합니다.

목차

커스터마이제이션 포인트 객체

views::repeat 라는 이름은 커스터마이제이션 포인트 객체 를 나타내며, 이는 함수 객체 의 const이며 리터럴 semiregular 클래스 타입입니다. 자세한 내용은 CustomizationPointObject 를 참조하십시오.

데이터 멤버

멤버 정의
movable-box  < W > value_ 뷰의 반복 요소
( 설명 전용 멤버 객체* )
Bound bound_ 센티넬 값
( 설명 전용 멤버 객체* )

멤버 함수

repeat_view 를 생성함
(public 멤버 함수)
repeat_view 의 시작 반복자를 얻음
(public 멤버 함수)
repeat_view 의 끝을 나타내는 센티널을 얻음
(public 멤버 함수)
크기가 있는 경우 repeat_view 의 크기를 얻음
(public 멤버 함수)
std::ranges::view_interface 로부터 상속됨
파생된 뷰가 비어 있는지 여부를 반환함 ( sized_range 또는 forward_range 를 만족하는 경우에만 제공됨)
( std::ranges::view_interface<D> 의 public 멤버 함수)
(C++23)
범위의 시작을 가리키는 상수 반복자를 반환함
( std::ranges::view_interface<D> 의 public 멤버 함수)
(C++23)
범위의 상수 반복자에 대한 센티널을 반환함
( std::ranges::view_interface<D> 의 public 멤버 함수)
파생된 뷰가 비어 있지 않은지 여부를 반환함 ( ranges::empty 가 적용 가능한 경우에만 제공됨)
( std::ranges::view_interface<D> 의 public 멤버 함수)
파생된 뷰의 첫 번째 요소를 반환함 ( forward_range 를 만족하는 경우 제공됨)
( std::ranges::view_interface<D> 의 public 멤버 함수)
파생된 뷰의 마지막 요소를 반환함 ( bidirectional_range common_range 를 만족하는 경우에만 제공됨)
( std::ranges::view_interface<D> 의 public 멤버 함수)
파생된 뷰의 n 번째 요소를 반환함 ( random_access_range 를 만족하는 경우에만 제공됨)
( std::ranges::view_interface<D> 의 public 멤버 함수)

std::ranges::repeat_view:: repeat_view

repeat_view ( ) requires std:: default_initializable < W > = default ;
(1) (C++23 이후)
constexpr explicit repeat_view ( const W & value, Bound bound = Bound ( ) ) ;
(2) (C++23 이후)
constexpr explicit repeat_view ( W && value, Bound bound = Bound ( ) ) ;
(3) (C++23 이후)
template < class ... WArgs , class ... BoundArgs >

requires std:: constructible_from < W, WArgs... >
&& std:: constructible_from < Bound, BoundArgs... >
constexpr explicit
repeat ( std:: piecewise_construct_t , std:: tuple < WArgs... > value_args,

std:: tuple < BoundArgs... > bound_args = std:: tuple <> { } ) ;
(4) (C++23 이후)
1) value_ 을 기본 초기화하고 bound_ 을 값 초기화합니다.
2) value_ value 로 초기화하고 bound_ bound 로 초기화합니다.
만약 Bound std::unreachable_sentinel_t 가 아니고 bool ( bound >= 0 ) false 인 경우, 동작은 정의되지 않습니다.
3) value_ std :: move ( value ) 로 초기화하고 bound_ bound 로 초기화합니다.
만약 Bound std::unreachable_sentinel_t 가 아니고 bool ( bound >= 0 ) false 인 경우, 동작은 정의되지 않습니다.
4) value_ std:: make_from_tuple < T > ( std :: move ( value_args ) ) 로 초기화하고, bound_ std:: make_from_tuple < Bound > ( std :: move ( bound_args ) ) 로 초기화합니다.
만약 Bound std::unreachable_sentinel_t 가 아니고 bool ( bound >= 0 ) false 인 경우, 동작은 정의되지 않습니다.

매개변수

value - 반복적으로 생성될 값
bound - 경계값
value_args - value_ 의 초기화자를 포함하는 튜플
bound_args - bound_ 의 초기화자를 포함하는 튜플

std::ranges::repeat_view:: begin

constexpr /*iterator*/ begin ( ) const ;
(C++23부터)

iterator  ( std:: addressof ( * value_  ) ) 을 반환합니다.

std::ranges::repeat_view:: end

constexpr /*iterator*/ end ( ) const
requires ( ! std:: same_as < Bound, std:: unreachable_sentinel_t > ) ;
(1) (since C++23)
constexpr std:: unreachable_sentinel_t end ( ) const ;
(2) (since C++23)
1) iterator 를 반환합니다 iterator  ( std:: addressof ( * value_  ) , bound_  ) .
2) std:: unreachable_sentinel 를 반환합니다.

std::ranges::repeat_view:: size

constexpr auto size ( ) const
requires ( ! std:: same_as < Bound, std:: unreachable_sentinel_t > ) ;
(C++23부터)

to-unsigned-like  ( bound_  ) 을 반환합니다.

추론 가이드

template < class W, class Bound = std:: unreachable_sentinel_t >
repeat_view ( W, Bound = Bound ( ) ) - > repeat_view < W, Bound > ;
(C++23부터)

중첩 클래스

반복자 타입
( 설명 전용 멤버 클래스* )

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_ranges_repeat 202207L (C++23) std::ranges::repeat_view

예제

#include <iostream>
#include <ranges>
#include <string_view>
using namespace std::literals;
int main()
{
    // bounded overload
    for (auto s : std::views::repeat("C++"sv, 3))
        std::cout << s << ' ';
    std::cout << '\n';
    // unbounded overload
    for (auto s : std::views::repeat("I know that you know that"sv)
                | std::views::take(3))
        std::cout << s << ' ';
    std::cout << "...\n";
}

출력:

C++ C++ C++
I know that you know that I know that you know that I know that you know that ...

결함 보고서

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

DR 적용 대상 게시된 동작 올바른 동작
LWG 4053 C++20 단항 호출 시 views::repeat 가 인수를 decay하지 않음 인수를 decay함
LWG 4054 C++20 repeat_view views::repeat 를 호출할 때
중첩된 repeat_view 를 생성하지 않음
중첩된
repeat_view 를 생성함

참고 항목

초기값을 반복적으로 증가시켜 생성된 시퀀스로 구성된 view
(클래스 템플릿) (커스터마이제이션 포인트 객체)