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) :
value
とbound
をコピーして、*this
に保持する - (3) :
value
をムーブし、bound
をコピーして、*this
に保持する - (4) : 値型
T
のコンストラクタ引数をタプルにまとめたvalue_args
と、繰り返し回数を表す型Bound
のコンストラクタ引数をタプルにまとめたbound_args
を転送して、オブジェクトを内部で構築して*this
に保持する
事前条件
- (1), (2) :
- 型
Bound
が型unreachable_sentinel_t
でないこと bound >= 0
であること
- 型
効果
- (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;
}
}
}
出力
hello
hello
hello
hello
hello
hello
aaa
aaa
aaa
バージョン
言語
- C++23
処理系
- Clang: 17 ✅
- GCC: 13 ✅
- ICC: ?
- Visual C++: 2022 Update 6 ✅