Skip to content

Latest commit

 

History

History
117 lines (96 loc) · 3.23 KB

File metadata and controls

117 lines (96 loc) · 3.23 KB

コンストラクタ

  • ranges[meta header]
  • std::ranges[meta namespace]
  • repeat_view[meta class]
  • function[meta id-type]
  • cpp23[meta cpp]
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) :
    • value_make_from_tuple<T>(std::move(value_args))で初期化する
    • bound_make_from_tuple<Bound>(std::move(bound_args))で初期化する
    • boundが型unreachable_sentinel_tである場合、もしくはbound < 0である場合、未定義動作を引き起こす

#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;
    }
  }
}
  • std::ranges::repeat_view[color ff0000]
  • std::views::repeat[color ff0000]

出力

hello
hello
hello

hello
hello
hello

aaa
aaa
aaa

バージョン

言語

  • C++23

処理系