|
| 1 | +# コンストラクタ |
| 2 | +* ranges[meta header] |
| 3 | +* std::ranges[meta namespace] |
| 4 | +* repeat_view[meta class] |
| 5 | +* function[meta id-type] |
| 6 | +* cpp23[meta cpp] |
| 7 | + |
| 8 | +```cpp |
| 9 | +repeat_view() |
| 10 | + requires default_initializable<T> = default; // (1) C++23 |
| 11 | + |
| 12 | +constexpr explicit |
| 13 | + repeat_view(const T& value, Bound bound = Bound()) |
| 14 | + requires copy_constructible<T>; // (2) C++23 |
| 15 | + |
| 16 | +constexpr explicit |
| 17 | + repeat_view(T&& value, Bound bound = Bound()); // (3) C++23 |
| 18 | + |
| 19 | +template <class... TArgs, class... BoundArgs> |
| 20 | + requires constructible_from<T, TArgs...> && |
| 21 | + constructible_from<Bound, BoundArgs...> |
| 22 | +constexpr explicit |
| 23 | + repeat_view(piecewise_construct_t, |
| 24 | + tuple<TArgs...> value_args, |
| 25 | + tuple<BoundArgs...> bound_args = tuple<>{}); // (4) C++23 |
| 26 | +``` |
| 27 | +
|
| 28 | +## 概要 |
| 29 | +[`repeat_view`](../repeat_view.md)オブジェクトを構築する。 |
| 30 | +
|
| 31 | +- (1) : デフォルト構築 |
| 32 | +- (2) : `value`と`bound`をコピーして、`*this`に保持する |
| 33 | +- (3) : `value`をムーブし、`bound`をコピーして、`*this`に保持する |
| 34 | +- (4) : 値型`T`のコンストラクタ引数をタプルにまとめた`value_args`と、繰り返し回数を表す型`Bound`のコンストラクタ引数をタプルにまとめた`bound_args`を転送して、オブジェクトを内部で構築して`*this`に保持する |
| 35 | +
|
| 36 | +
|
| 37 | +## 事前条件 |
| 38 | +- (1), (2) : |
| 39 | + - 型`Bound`が型[`unreachable_sentinel_t`](/reference/iterator/unreachable_sentinel_t.md)でないこと |
| 40 | + - `bound >= 0`であること |
| 41 | +
|
| 42 | +
|
| 43 | +## 効果 |
| 44 | +
|
| 45 | +- (2) : `value_`を`value`で初期化する |
| 46 | +- (3) : `value_`を[`std::move`](/reference/utility/move.md)`(value)`で初期化する |
| 47 | +- (4) : |
| 48 | + - `value_`を[`make_from_tuple`](/reference/tuple/make_from_tuple.md)`<T>(`[`std::move`](/reference/utility/move.md)`(value_args))`で初期化する |
| 49 | + - `bound_`を[`make_from_tuple`](/reference/tuple/make_from_tuple.md)`<Bound>(`[`std::move`](/reference/utility/move.md)`(bound_args))`で初期化する |
| 50 | + - `bound`が型`unreachable_sentinel_t`である場合、もしくは`bound < 0`である場合、未定義動作を引き起こす |
| 51 | +
|
| 52 | +
|
| 53 | +## 例 |
| 54 | +```cpp example |
| 55 | +#include <iostream> |
| 56 | +#include <ranges> |
| 57 | +#include <string> |
| 58 | +
|
| 59 | +int main() { |
| 60 | + // (2) コピー構築 |
| 61 | + { |
| 62 | + std::string s1 = "hello"; |
| 63 | + for (const std::string& x : std::views::repeat(s1, 3)) { |
| 64 | + std::cout << x << std::endl; |
| 65 | + } |
| 66 | + } |
| 67 | + std::cout << std::endl; |
| 68 | +
|
| 69 | + // (3) ムーブ構築 |
| 70 | + { |
| 71 | + std::string s1 = "hello"; |
| 72 | + for (const std::string& x : std::views::repeat(std::move(s1), 3)) { |
| 73 | + std::cout << x << std::endl; |
| 74 | + } |
| 75 | + } |
| 76 | + std::cout << std::endl; |
| 77 | +
|
| 78 | + // (4) コンストラクタ引数から構築 |
| 79 | + { |
| 80 | + auto r = std::ranges::repeat_view<std::string, int>{ |
| 81 | + std::piecewise_construct, |
| 82 | + std::make_tuple(3, 'a'), |
| 83 | + std::make_tuple(3) |
| 84 | + }; |
| 85 | + for (const std::string& x : r) { |
| 86 | + std::cout << x << std::endl; |
| 87 | + } |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | +* std::ranges::repeat_view[color ff0000] |
| 92 | +* std::views::repeat[color ff0000] |
| 93 | + |
| 94 | +### 出力 |
| 95 | +``` |
| 96 | +hello |
| 97 | +hello |
| 98 | +hello |
| 99 | +
|
| 100 | +hello |
| 101 | +hello |
| 102 | +hello |
| 103 | +
|
| 104 | +aaa |
| 105 | +aaa |
| 106 | +aaa |
| 107 | +``` |
| 108 | + |
| 109 | +## バージョン |
| 110 | +### 言語 |
| 111 | +- C++23 |
| 112 | + |
| 113 | +### 処理系 |
| 114 | +- [Clang](/implementation.md#clang): 17 [mark verified] |
| 115 | +- [GCC](/implementation.md#gcc): 13 [mark verified] |
| 116 | +- [ICC](/implementation.md#icc): ? |
| 117 | +- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6 [mark verified] |
0 commit comments