最終更新日時(UTC):
が更新

履歴 編集

function
<ranges>

std::ranges::repeat_view::コンストラクタ(C++23)

repeat_view()
  requires default_initializable<T> = default;       // (1) C++23

constexpr explicit
  repeat_view(const T& value, Bound bound = Bound())
    requires copy_constructible<T>;                  // (2) C++23

constexpr explicit
  repeat_view(T&& value, Bound bound = Bound());     // (3) C++23

template <class... TArgs, class... BoundArgs>
  requires constructible_from<T, TArgs...> &&
           constructible_from<Bound, BoundArgs...>
constexpr explicit
  repeat_view(piecewise_construct_t,
              tuple<TArgs...> value_args,
              tuple<BoundArgs...> bound_args = tuple<>{}); // (4) C++23

概要

repeat_viewオブジェクトを構築する。

  • (1) : デフォルト構築
  • (2) : valueboundをコピーして、*thisに保持する
  • (3) : valueをムーブし、boundをコピーして、*thisに保持する
  • (4) : 値型Tのコンストラクタ引数をタプルにまとめたvalue_argsと、繰り返し回数を表す型Boundのコンストラクタ引数をタプルにまとめたbound_argsを転送して、オブジェクトを内部で構築して*thisに保持する

事前条件

効果

  • (2) : value_valueで初期化する
  • (3) : value_std::move(value)で初期化する
  • (4) :

#include <iostream>
#include <ranges>
#include <string>

int main() {
  // (2) コピー構築
  {
    std::string s1 = "hello";
    for (const std::string& x : std::views::repeat(s1, 3)) {
      std::cout << x << std::endl;
    }
  }
  std::cout << std::endl;

  // (3) ムーブ構築
  {
    std::string s1 = "hello";
    for (const std::string& x : std::views::repeat(std::move(s1), 3)) {
      std::cout << x << std::endl;
    }
  }
  std::cout << std::endl;

  // (4) コンストラクタ引数から構築
  {
    auto r = std::ranges::repeat_view<std::string, int>{
        std::piecewise_construct,
        std::make_tuple(3, 'a'),
        std::make_tuple(3)
    };
    for (const std::string& x : r) {
      std::cout << x << std::endl;
    }
  }
}

出力

hello
hello
hello

hello
hello
hello

aaa
aaa
aaa

バージョン

言語

  • C++23

処理系