Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# repeat_view | ||
* ranges[meta header] | ||
* std::ranges[meta namespace] | ||
* class template[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std::ranges { | ||
template<move_constructible T, semiregular Bound = unreachable_sentinel_t> | ||
requires (is_object_v<T> && same_as<T, remove_cv_t<T>> && | ||
(is-integer-like<Bound> || same_as<Bound, unreachable_sentinel_t>)) | ||
class repeat_view : public view_interface<repeat_view<T, Bound>> { …… }; // (1) | ||
|
||
namespace views { | ||
inline constexpr /*unspecified*/ repeat = /*unspecified*/; // (2) | ||
} | ||
} | ||
``` | ||
* move_constructible[link /reference/concepts/move_constructible.md] | ||
* semiregular[link /reference/concepts/semiregular.md] | ||
* unreachable_sentinel_t[link /reference/iterator/unreachable_sentinel_t.md] | ||
* is_object_v[link /reference/type_traits/is_object.md] | ||
* same_as[link /reference/concepts/same_as.md] | ||
* remove_cv_t[link /reference/type_traits/remove_cv.md] | ||
* is-integer-like[link /reference/iterator/is_integer_like.md] | ||
* view_interface[link view_interface.md] | ||
## 概要 | ||
- (1): 指定した値を指定回数繰り返す[`view`](view.md) | ||
- (2): `repeat_view`を生成するカスタマイゼーションポイントオブジェクト | ||
回数を省略した場合、無限長となる。 | ||
### Rangeコンセプト | ||
| borrowed | sized | output | input | forward | bidirectional | random_access | contiguous | common | viewable | view | | ||
|----------|-------|--------|-------|---------|---------------|---------------|------------|--------|----------|------| | ||
| | (1) | | ○ | ○ | ○ | ○ | | (1) | ○ | ○ | | ||
- (1) `Bound = unreachable_sentinel_t` ではない場合 | ||
## 効果 | ||
- 式`views::repear(E)`の効果は`repeat_view(E)`と等しい。 | ||
- 式`views::repear(E, F)`の効果は`repeat_view(E, F)`と等しい。 | ||
## メンバ関数 | ||
| 名前 | 説明 | 対応バージョン | | ||
|--------------------------------------------------|----------------------------------|----------------| | ||
| [`(constructor)`](repeat_view/op_constructor.md.nolink) | コンストラクタ | C++23 | | ||
| [`begin`](repeat_view/begin.md.nolink) | 先頭を指すイテレータを取得する | C++23 | | ||
| [`end`](repeat_view/end.md.nolink) | 番兵を取得する | C++23 | | ||
| [`size`](repeat_view/data.md.nolink) | 配列の先頭へのポインタを取得する | C++23 | | ||
## 継承しているメンバ関数 | ||
| 名前 | 説明 | 対応バージョン | | ||
|----------------------------------------------|------------------------------ ----|----------------| | ||
| [`operator bool`](view_interface/op_bool.md) | Rangeが空でないかどうかを判定する | C++23 | | ||
| [`front`](view_interface/front.md) | 先頭要素への参照を取得する | C++23 | | ||
| [`back`](view_interface/back.md) | 末尾要素への参照を取得する | C++23 | | ||
| [`operator[]`](view_interface/op_at.md) | 要素へアクセスする | C++23 | | ||
## メンバ型 | ||
| 名前 | 説明 | 対応バージョン | | ||
|-------------------------------------------|------------------------------|----------------| | ||
| [`iterator`](repeat_view/iterator.md) | イテレータ型(説明専用) | C++23 | | ||
## 推論補助 | ||
| 名前 | 説明 | 対応バージョン | | ||
|-------------------------------------------------------|------------------------------|----------------| | ||
| [`(deduction_guide)`](repeat_view/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++23 | | ||
## 例 | ||
```cpp example | ||
#include <ranges> | ||
#include <iostream> | ||
int main() { | ||
using namespace std; | ||
for(int n : views::repeat(42, 3)) { | ||
cout << n << ' '; | ||
} | ||
} | ||
``` | ||
* views::repeat[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
42 42 42 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ? | ||
- [GCC](/implementation.md#gcc): ? | ||
- [ICC](/implementation.md#icc): ? | ||
- [Visual C++](/implementation.md#visual_cpp): ? | ||
|
||
## 参照 | ||
- [N4917 26 Ranges library](https://timsong-cpp.github.io/cppwp/ranges) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# iterator | ||
* ranges[meta header] | ||
* std::ranges[meta namespace] | ||
* repeat_view[meta class] | ||
* class template[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
## 概要 | ||
|
||
[`repeat_view`](../repeat_view.md)のイテレータ。 | ||
|
||
このクラスの名前は規定されておらず、振る舞いのみが規定されている。 | ||
|
||
このクラスの型を取得したい場合、[`iterator_t`](../iterator_t.md)を使用できる。 | ||
|
||
|
||
## 実装例 | ||
|
||
```cpp | ||
namespace std::ranges { | ||
template<move_constructible T, semiregular Bound = unreachable_sentinel_t> | ||
requires (is_object_v<T> && same_as<T, remove_cv_t<T>> && | ||
(is-integer-like<Bound> || same_as<Bound, unreachable_sentinel_t>)) | ||
class repeat_view<T, Bound>::iterator { | ||
private: | ||
using index_type = conditional_t<same_as<Bound, unreachable_sentinel_t>, ptrdiff_t, Bound>; | ||
const T* value_ = nullptr;P | ||
index_type current_ = index_type(); | ||
|
||
constexpr explicit iterator(const T* value, index_type b = index_type()) | ||
: value_{value} | ||
, current_{b} | ||
{ | ||
} | ||
|
||
public: | ||
using iterator_concept = random_access_iterator_tag; | ||
using iterator_category = random_access_iterator_tag; | ||
using value_type = T; | ||
using difference_type = conditional_t<is-signed-integer-like<index_type>, | ||
index_type, | ||
iota_diff_t(index_type)>; | ||
|
||
iterator() = default; | ||
|
||
constexpr const T& operator*() const noexcept { | ||
return *value_; | ||
} | ||
|
||
constexpr iterator& operator++() { | ||
++current_; | ||
return *this; | ||
} | ||
constexpr iterator operator++(int) { | ||
auto tmp = *this; | ||
++*this; | ||
return tmp; | ||
} | ||
|
||
constexpr iterator& operator--() { | ||
--current_; | ||
return *this; | ||
} | ||
constexpr iterator operator--(int) { | ||
auto tmp = *this; | ||
--*this; | ||
return tmp; | ||
} | ||
|
||
constexpr iterator& operator+=(difference_type n) { | ||
current_ += n; | ||
return *this; | ||
} | ||
constexpr iterator& operator-=(difference_type n) { | ||
current_ -= n; | ||
return *this; | ||
} | ||
constexpr const T& operator[](difference_type n) const noexcept { | ||
return *(*this + n); | ||
} | ||
|
||
friend constexpr bool operator==(const iterator& x, const iterator& y) { | ||
return x.current_ == y.current_; | ||
} | ||
friend constexpr auto operator<=>(const iterator& x, const iterator& y) { | ||
return x.current_ <=> y.current_; | ||
} | ||
|
||
friend constexpr iterator operator+(iterator i, difference_type n) { | ||
i += n; | ||
return i; | ||
} | ||
friend constexpr iterator operator+(difference_type n, iterator i) { | ||
i += n; | ||
return i; | ||
} | ||
|
||
friend constexpr iterator operator-(iterator i, difference_type n) { | ||
i -= n; | ||
return i; | ||
} | ||
friend constexpr difference_type operator-(const iterator& x, const iterator& y) { | ||
return static_cast<difference_type>(x.current_) - static_cast<difference_type>(y.current_); | ||
} | ||
}; | ||
} | ||
``` | ||
* move_constructible[link /reference/concepts/move_constructible.md] | ||
* semiregular[link /reference/concepts/semiregular.md] | ||
* unreachable_sentinel_t[link /reference/iterator/unreachable_sentinel_t.md] | ||
* is_object_v[link /reference/type_traits/is_object.md] | ||
* same_as[link /reference/concepts/same_as.md] | ||
* remove_cv_t[link /reference/type_traits/remove_cv.md] | ||
* is-integer-like[link /reference/iterator/is_integer_like.md] | ||
* repeat_view[link ../repeat_view.md] | ||
* conditional_t[link /reference/type_traits/conditional.md] | ||
* ptrdiff_t[link /reference/stddef/ptrdiff_t.md] | ||
* random_access_iterator_tag[link /reference/iterator/iterator_tag.md] | ||
* is-signed-integer-like[link /reference/iterator/is_integer_like.md] | ||
* iota_diff_t[link /reference/ranges/iota_view/iota_diff_t.md] | ||
* incrementable[link /reference/iterator/incrementable.md] | ||
* weakly-equality-comparable-with[link /reference/concepts/equality_comparable.md] | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ? | ||
- [GCC](/implementation.md#gcc): ? | ||
- [ICC](/implementation.md#icc): ? | ||
- [Visual C++](/implementation.md#visual_cpp): ? | ||
|
||
## 参照 | ||
- [N4917 26 Ranges library](https://timsong-cpp.github.io/cppwp/ranges) |