Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make_const_iterator/make_const_sentinel追加 #1023
- Loading branch information
Showing
3 changed files
with
138 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,66 @@ | ||
# make_const_iterator | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
template<input_iterator I> | ||
constexpr const_iterator<I> make_const_iterator(I it); | ||
} | ||
``` | ||
* input_iterator[link input_iterator.md] | ||
* const_iterator[link const_iterator.md.nolink] | ||
## 概要 | ||
`basic_const_iterator`のヘルパ関数。 | ||
## 戻り値 | ||
```cpp | ||
return it; | ||
``` | ||
|
||
戻り値型は必ずしも`basic_const_iterator`の特殊化になるわけではない。 | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <vector> | ||
#include <memory> | ||
#include <iterator> | ||
|
||
int main() { | ||
std::vector vec = {1, 2, 3, 4, 5}; | ||
|
||
auto cit = std::make_const_iterator(vec.begin()); | ||
auto cse = std::make_const_sentinel(vec.end()); | ||
|
||
for (auto& n : std::ranges::subrange{cit, cse}) { | ||
std::cout << n << ", "; | ||
// 変更できない | ||
// n = 0; | ||
} | ||
} | ||
``` | ||
* std::make_const_iterator[color ff0000] | ||
* make_const_sentinel[link make_const_sentinel.md] | ||
|
||
### 出力 | ||
``` | ||
1, 2, 3, 4, 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) |
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,70 @@ | ||
# make_const_sentinel | ||
* iterator[meta header] | ||
* std[meta namespace] | ||
* function[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
template<semiregular S> | ||
constexpr const_sentinel<S> make_const_sentinel(S s); | ||
} | ||
``` | ||
* semiregular[link semiregular.md] | ||
* const_sentinel[link const_sentinel.md.nolink] | ||
## 概要 | ||
`basic_const_iterator`のヘルパ関数。特に、イテレータではないような番兵を`basic_const_iterator`の番兵型へと変換するのに使用する。 | ||
## 戻り値 | ||
```cpp | ||
return s; | ||
``` | ||
|
||
戻り値型は必ずしも`basic_const_iterator`の特殊化になるわけではない。 | ||
|
||
## 例 | ||
```cpp example | ||
#include <iostream> | ||
#include <vector> | ||
#include <iterator> | ||
#include <algorithm> | ||
|
||
int main() { | ||
std::vector vec = {1, 2, 3, 4, 11, 5, 6, 22}; | ||
|
||
auto cit = std::make_const_iterator(rng.begin()); | ||
auto cse = std::make_const_sentinel(std::unreachable_sentinel); // unreachable_sentinelはイテレータではない汎用の番兵 | ||
|
||
auto pos = std::ranges::find_if(cit, cse, [](auto& n) { | ||
// 述語中で誤って変更してしまうことを防止する | ||
// n = 0; | ||
return 10 <= n; | ||
}); | ||
|
||
std::cout << *pos; | ||
} | ||
``` | ||
* std::make_const_sentinel[color ff0000] | ||
* make_const_iterator[link make_const_iterator.md] | ||
* unreachable_sentinel[link unreachable_sentinel_t.md] | ||
|
||
### 出力 | ||
``` | ||
11 | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- 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) |
396b2b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
間違い #1084