Skip to content

Commit

Permalink
as_const_view::size()追加 #1084
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed Sep 9, 2023
1 parent dbc7c10 commit 1fff32a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion reference/ranges/as_const_view.md
Expand Up @@ -49,7 +49,7 @@ namespace std::ranges {
| [`base`](as_const_view/base.md) | `V`の参照を取得する | C++23 |
| [`begin`](as_const_view/begin.md.nolink) | 先頭を指すイテレータを取得する | C++23 |
| [`end`](as_const_view/end.md.nolink) | 番兵を取得する | C++23 |
| [`size`](as_const_view/size.md.nolink) | 要素数を取得する | C++23 |
| [`size`](as_const_view/size.md) | 要素数を取得する | C++23 |
## 継承しているメンバ関数
Expand Down
63 changes: 63 additions & 0 deletions reference/ranges/as_const_view/size.md
@@ -0,0 +1,63 @@
# size
* ranges[meta header]
* std::ranges[meta namespace]
* as_const_view[meta class]
* function[meta id-type]
* cpp23[meta cpp]

```cpp
constexpr auto size() requires sized_range<V>; // (1)
constexpr auto size() const requires sized_range<const V>; // (2)
```
* sized_range[link /reference/ranges/sized_range.md]

## 概要

`view`の要素数を取得する。

この関数で得られる`as_const_view`の要素数は、元のRange(`V`)の要素数と一致する。

## 戻り値

入力`view``V`)のオブジェクトを`base_`というメンバに保持するとして

- (1) : `return ranges::size(base_);`
- (2) : `return ranges::size(base_);`

##

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

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

std::ranges::as_const_view acv{vec};

std::cout << acv.size() << '\n';
std::cout << vec.size() << '\n';
}
```
* size[color ff0000]

### 出力

```
5
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)

0 comments on commit 1fff32a

Please sign in to comment.