Skip to content

Commit

Permalink
span : P2278R4対応 #1084
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Jul 19, 2023
1 parent 97b792b commit adf4a90
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 2 deletions.
11 changes: 9 additions & 2 deletions reference/span/span.md
Expand Up @@ -106,6 +106,10 @@ namespace std {
| [`end`](span/end.md) | 末尾要素の次を指すイテレータを取得する | C++20 |
| [`rbegin`](span/rbegin.md) | 末尾要素を指す逆順イテレータを取得する | C++20 |
| [`rend`](span/rend.md) | 先頭要素の前を指す逆順イテレータを取得する | C++20 |
| [`cbegin`](span/cbegin.md) | 先頭の要素を指す読み取り専用イテレータを取得する | C++23 |
| [`cend`](span/cend.md) | 末尾の次を指す読み取り専用イテレータを取得する | C++23 |
| [`crbegin`](span/crbegin.md) | 末尾を指す読み取り専用逆イテレータを取得する | C++23 |
| [`crend`](span/crend.md) | 先頭の前を指す読み取り専用逆イテレータを取得する | C++23 |
### メンバ定数
Expand All @@ -129,6 +133,8 @@ namespace std {
| `const_reference` | `const`参照型 `const element_type&` | C++20 |
| `iterator` | 実装定義のイテレータ型。[`contiguous_iterator`](/reference/iterator/contiguous_iterator.md)、[`random_access_iterator`](/reference/iterator/random_access_iterator.md)、constexprイテレータのモデルであり、コンテナのイテレータに対するすべての要件を満たす | C++20 |
| `reverse_iterator` | 逆順イテレータ [`reverse_iterator`](/reference/iterator/reverse_iterator.md)`<iterator>` | C++20 |
| `const_iterator` | 読み取り専用イテレータ [`std::const_iterator`](/reference/iterator/const_iterator.md.nolink)`<iterator>` | C++23 |
| `const_reverse_iterator` | 読み取り専用逆イテレータ [`std::const_iterator`](/reference/iterator/const_iterator.md.nolink)`<reverse_iterator>` | C++23 |
## 非メンバ関数
Expand Down Expand Up @@ -259,8 +265,8 @@ int main()
### 処理系
- [Clang](/implementation.md#clang): 9.0
- [GCC](/implementation.md#gcc): ??
- [Visual C++](/implementation.md#visual_cpp): ??
- [GCC](/implementation.md#gcc): 10.1
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 6
## 参照
Expand All @@ -280,3 +286,4 @@ int main()
- [P2325R3 Views should not be required to be default constructible](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2325r3.html)
- [Require `span` & `basic_string_view` to be Trivially Copyable](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2251r1.pdf)
- C++23から、トリビアルコピー可能が保証される。
- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)
63 changes: 63 additions & 0 deletions reference/span/span/cbegin.md
@@ -0,0 +1,63 @@
# cbegin
* span[meta header]
* std[meta namespace]
* span[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr const_iterator cbegin() const noexcept;
```
* const_iterator[link /reference/iterator/const_iterator.md.nolink]

## 概要
先頭要素を指す読み取り専用イテレータを取得する。


## 戻り値

```cpp
return begin();
```
* begin[link ./begin.md]


## 例外
投げない

##
```cpp example
#include <iostream>
#include <span>
#include <vector>

int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::span<int, 5> sp{v};

auto cit = sp.cbegin();

std::cout << *cit << '\n';

// これはできない
// *cit = 0;
}
```
* cbegin()[color ff0000]

### 出力
```
1
```

## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6

## 参照
- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)
77 changes: 77 additions & 0 deletions reference/span/span/cend.md
@@ -0,0 +1,77 @@
# cend
* span[meta header]
* std[meta namespace]
* span[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr const_iterator cend() const noexcept;
```
* const_iterator[link /reference/iterator/const_iterator.md.nolink]

## 概要
末尾要素の次を指すイテレータを取得する。


## 戻り値

```cpp
return end();
```
* end[link ./end.md]


## 例外
投げない

##
```cpp example
#include <iostream>
#include <span>
#include <vector>

template<typename I, std::sentinel_for<I> S>
bool is_iter_pair(I, S) {
return true;
}

bool is_iter_pair(...) {
return false;
}

int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::span<int, 5> sp{v};

auto cit = sp.cend();
--cit;

std::cout << *cit << '\n';

std::cout << std::boolalpha;
std::cout << is_iter_pair(sp.cbegin(), sp.cend()) << '\n';
std::cout << is_iter_pair(sp.begin(), sp.cend()) << '\n';
}
```
* cend()[color ff0000]
* sentinel_for[link /reference/iterator/sentinel_for.md]
### 出力
```
5
true
true
```
## バージョン
### 言語
- C++23
### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6
## 参照
- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)
63 changes: 63 additions & 0 deletions reference/span/span/crbegin.md
@@ -0,0 +1,63 @@
# crbegin
* span[meta header]
* std[meta namespace]
* span[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr const_reverse_iterator crbegin() const noexcept;
```
* const_iterator[link /reference/iterator/const_iterator.md.nolink]

## 概要
末尾要素の次を指すイテレータを取得する。


## 戻り値

```cpp
return rbegin();
```
* rbegin[link ./rbegin.md]


## 例外
投げない

##
```cpp example
#include <iostream>
#include <span>
#include <vector>

int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::span<int, 5> sp{v};

auto cit = sp.crbegin();

std::cout << *cit << '\n';

// これはできない
// *cit = 0;
}
```
* crbegin()[color ff0000]

### 出力
```
5
```

## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6

## 参照
- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)
77 changes: 77 additions & 0 deletions reference/span/span/crend.md
@@ -0,0 +1,77 @@
# crend
* span[meta header]
* std[meta namespace]
* span[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr const_reverse_iterator crend() const noexcept;
```
* const_iterator[link /reference/iterator/const_iterator.md.nolink]

## 概要
末尾要素の次を指すイテレータを取得する。


## 戻り値

```cpp
return rend();
```
* rend[link ./rend.md]


## 例外
投げない

##
```cpp example
#include <iostream>
#include <span>
#include <vector>

template<typename I, std::sentinel_for<I> S>
bool is_iter_pair(I, S) {
return true;
}

bool is_iter_pair(...) {
return false;
}

int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
std::span<int, 5> sp{v};

auto cit = sp.crend();
--cit;

std::cout << *cit << '\n';

std::cout << std::boolalpha;
std::cout << is_iter_pair(sp.crbegin(), sp.crend()) << '\n';
std::cout << is_iter_pair(sp.rbegin(), sp.crend()) << '\n';
}
```
* crend()[color ff0000]
* sentinel_for[link /reference/iterator/sentinel_for.md]
### 出力
```
1
true
true
```
## バージョン
### 言語
- C++23
### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): 13.1
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6
## 参照
- [P2278R4 `cbegin` should always return a constant iterator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2278r4.html)

0 comments on commit adf4a90

Please sign in to comment.