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) 同じ値を繰り返し生成することで要素のシーケンスを生成するレンジファクトリ。有界または無界(無限)のいずれかになります。
2) views :: repeat ( e ) および views :: repeat ( e, f ) は、任意の適切な部分式 e および f に対して、それぞれ repeat_view < std:: decay_t < decltype ( ( E ) ) >> ( e ) および repeat_view ( 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 member function)
repeat_view の先頭イテレータを取得する
(public member function)
repeat_view の終端を示すセンチネルを取得する
(public member function)
repeat_view のサイズを取得する(サイズ指定可能な場合)
(public member function)
std::ranges::view_interface から継承
派生ビューが空かどうかを返す( sized_range または forward_range を満たす場合のみ提供)
( std::ranges::view_interface<D> のpublic member function)
(C++23)
範囲の先頭を指す定数イテレータを返す
( std::ranges::view_interface<D> のpublic member function)
(C++23)
範囲の定数イテレータのセンチネルを返す
( std::ranges::view_interface<D> のpublic member function)
派生ビューが空でないかどうかを返す( ranges::empty が適用可能な場合のみ提供)
( std::ranges::view_interface<D> のpublic member function)
派生ビューの先頭要素を返す( forward_range を満たす場合に提供)
( std::ranges::view_interface<D> のpublic member function)
派生ビューの末尾要素を返す( bidirectional_range かつ common_range を満たす場合のみ提供)
( std::ranges::view_interface<D> のpublic member function)
派生ビューの n 番目 の要素を返す( random_access_range を満たす場合のみ提供)
( std::ranges::view_interface<D> のpublic member function)

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  ( 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()
{
    // 境界付きオーバーロード
    for (auto s : std::views::repeat("C++"sv, 3))
        std::cout << s << ' ';
    std::cout << '\n';
    // 境界なしオーバーロード
    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 初期値を繰り返しインクリメントして生成されるシーケンスからなる
(クラステンプレート) (カスタマイゼーションポイントオブジェクト)