Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
as_const_view : コンストラクタとbase追加 #1084
- Loading branch information
Showing
3 changed files
with
133 additions
and
2 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,71 @@ | ||
# base | ||
* ranges[meta header] | ||
* std::ranges[meta namespace] | ||
* as_const_view[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
constexpr V base() const & requires copy_constructible<V>; // (1) | ||
constexpr V base() &&; // (2) | ||
``` | ||
* copy_constructible[link /reference/concepts/copy_constructible.md] | ||
|
||
## 概要 | ||
|
||
メンバ変数として保持している、元の`view`を取得する。 | ||
|
||
## 戻り値 | ||
|
||
入力`view`(`V`)のオブジェクトを`base_`というメンバに保持するとして | ||
|
||
- (1) : `return base_;` | ||
- (2) : `return std::move(base_);` | ||
|
||
## 例 | ||
|
||
```cpp example | ||
#include <iterator> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
int main() { | ||
using std::ranges::view; | ||
|
||
std::vector<int> vec = {1, 2, 3, 4, 5}; | ||
|
||
std::ranges::as_const_view acv{vec}; | ||
|
||
// (1) コピーして取得 | ||
view auto b1 = acv.base(); | ||
|
||
// (2) ムーブして取得 | ||
view auto b2 = std::move(acv).base(); | ||
|
||
// 得られるのは元のRangeではなく、あくまでview | ||
static_assert(not std::same_as<decltype(b1), std::vector<int>>); | ||
static_assert( std::same_as<decltype(b1), std::ranges::ref_view<std::vector<int>>>); | ||
static_assert( std::same_as<decltype(b2), std::ranges::ref_view<std::vector<int>>>); | ||
} | ||
``` | ||
* base[color ff0000] | ||
* same_as[link /reference/concepts/same_as.md] | ||
* ref_view[link /reference/ranges/ref_view.md] | ||
|
||
### 出力 | ||
|
||
``` | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |
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,60 @@ | ||
# コンストラクタ | ||
* ranges[meta header] | ||
* std::ranges[meta namespace] | ||
* as_const_view[meta class] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
as_const_view() requires default_initializable<V> = default; // (1) | ||
|
||
constexpr explicit as_const_view(V base); // (2) | ||
``` | ||
* default_initializable[link /reference/concepts/default_initializable.md] | ||
## 概要 | ||
`as_const_view`オブジェクトを構築する。 | ||
## 効果 | ||
入力`view`(`V`)のオブジェクトを`base_`というメンバに保持するとして | ||
- (1) : `base_`をデフォルト構築する | ||
- (2) : `base_`を`std::move(base)`で初期化する | ||
## 例 | ||
```cpp example | ||
#include <ranges> | ||
#include <vector> | ||
int main() { | ||
using std::ranges::as_const_view; | ||
std::vector<int> vec = {1, 2, 3, 4, 5}; | ||
// (1) デフォルト構築 | ||
as_const_view<std::views::all_t<std::vector<int>>> v1{}; | ||
// (2) viewを入力して構築 | ||
as_const_view v2{vec}; | ||
} | ||
``` | ||
* as_const_view[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |