Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions reference/algorithm/ranges_adjacent_find.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,45 @@ namespace std::ranges {
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
constexpr borrowed_iterator_t<R>
adjacent_find(R&& r, Pred pred = {}, Proj proj = {}); // (2) C++20

template <execution-policy Ep,
random_access_iterator I,
sized_sentinel_for<I> S,
class Proj = identity,
indirect_binary_predicate<projected<I, Proj>,
projected<I, Proj>> Pred = ranges::equal_to>
I adjacent_find(Ep&& exec,
I first,
S last,
Pred pred = {},
Proj proj = {}); // (3) C++26

template <execution-policy Ep,
sized-random-access-range R,
class Proj = identity,
indirect_binary_predicate<projected<iterator_t<R>, Proj>,
projected<iterator_t<R>, Proj>> Pred = ranges::equal_to>
borrowed_iterator_t<R>
adjacent_find(Ep&& exec,
R&& r,
Pred pred = {},
Proj proj = {}); // (4) C++26
}
```
* borrowed_iterator_t[link /reference/ranges/borrowed_iterator_t.md]
* execution-policy[link /reference/execution/execution-policy.md]
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* sized_sentinel_for[link /reference/iterator/sized_sentinel_for.md]
* sized-random-access-range[link /reference/ranges/sized-random-access-range.md]


## 概要
隣接する要素で条件を満たしている最初の要素を検索する。

- (1): イテレータ範囲を指定する
- (2): Rangeを直接指定する
- (3): (1)の並列アルゴリズム版。実行ポリシーを指定する
- (4): (2)の並列アルゴリズム版。実行ポリシーを指定する

このアルゴリズムは、範囲の先頭から1つづつ進みながら隣接するペアに対して条件を満たすかをチェックし、その条件を満たす最初の要素へのイテレータを返す。指定された条件を満たしているかをチェックされるのは、現在位置にある要素とその次の位置にある要素の2つについてであり、1つの要素は最大2回参照される。

Expand Down Expand Up @@ -61,6 +90,7 @@ namespace std::ranges {


## 例
### 基本的な使い方
```cpp example
#include <algorithm>
#include <iterator>
Expand All @@ -83,13 +113,13 @@ int main() {
* std::ranges::distance[link /reference/iterator/ranges_distance.md]
* std::ranges::adjacent_find[color ff0000]

### 出力
#### 出力
```
found: index==2
*it == *(it+1): true
```

### 動作イメージ
#### 動作イメージ

```
|0 1 2 3 4 5 6| : index
Expand All @@ -102,6 +132,32 @@ found: index==2
[2, 2]
```

### 並列アルゴリズムの例 (C++26)
```cpp example
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>

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

// 並列に同じ値が連続している最初の要素を検索する
auto it = std::ranges::adjacent_find(std::execution::par, v);
if (it == v.end()) {
std::cout << "not found" << std::endl;
} else {
std::cout << "found: index==" << std::distance(v.begin(), it) << std::endl;
}
}
```
* std::ranges::adjacent_find[color ff0000]

#### 出力
```
found: index==2
```

## 実装例
```cpp
struct adjacent_find_impl {
Expand Down Expand Up @@ -144,3 +200,4 @@ inline constexpr adjacent_find_impl adjacent_find;

## 参照
- [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms)
- [P3179R9 C++ parallel range algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3179r9.html)
55 changes: 54 additions & 1 deletion reference/algorithm/ranges_all_of.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,40 @@ namespace std::ranges {
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
constexpr bool
all_of(R&& r, Pred pred, Proj proj = {}); // (2) C++20

template <execution-policy Ep,
random_access_iterator I,
sized_sentinel_for<I> S,
class Proj = identity,
indirect_unary_predicate<projected<I, Proj>> Pred>
bool all_of(Ep&& exec,
I first,
S last,
Pred pred,
Proj proj = {}); // (3) C++26

template <execution-policy Ep,
sized-random-access-range R,
class Proj = identity,
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
bool all_of(Ep&& exec,
R&& r,
Pred pred,
Proj proj = {}); // (4) C++26
}
```
* execution-policy[link /reference/execution/execution-policy.md]
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* sized_sentinel_for[link /reference/iterator/sized_sentinel_for.md]
* sized-random-access-range[link /reference/ranges/sized-random-access-range.md]

## 概要
範囲の全ての要素が条件を満たすかを判定する。

- (1): イテレータ範囲を指定する
- (2): Rangeを直接指定する
- (3): (1)の並列アルゴリズム版。実行ポリシーを指定する
- (4): (2)の並列アルゴリズム版。実行ポリシーを指定する

## テンプレートパラメータ制約
- (1):
Expand All @@ -43,6 +69,7 @@ namespace std::ranges {
最大で `last - first` 回 `proj` と `pred` を実行する。

## 例
### 基本的な使い方
```cpp example
#include <algorithm>
#include <iostream>
Expand All @@ -64,12 +91,37 @@ int main() {
```
* std::ranges::all_of[color ff0000]

### 出力
#### 出力
```
true
false
```

### 並列アルゴリズムの例 (C++26)
```cpp example
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>

int main() {
std::vector<int> v = {2, 4, 6, 8, 10};

std::cout << std::boolalpha;

// 並列に全ての要素が偶数であるかを判定
bool result = std::ranges::all_of(std::execution::par, v,
[](int x) { return x % 2 == 0; });
std::cout << result << std::endl;
}
```
* std::ranges::all_of[color ff0000]

#### 出力
```
true
```

## 実装例
```cpp
struct all_of_impl {
Expand Down Expand Up @@ -111,3 +163,4 @@ inline constexpr all_of_impl all_of;

## 参照
- [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms)
- [P3179R9 C++ parallel range algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3179r9.html)
55 changes: 54 additions & 1 deletion reference/algorithm/ranges_any_of.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,40 @@ namespace std::ranges {
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
constexpr bool
any_of(R&& r, Pred pred, Proj proj = {}); // (2) C++20

template <execution-policy Ep,
random_access_iterator I,
sized_sentinel_for<I> S,
class Proj = identity,
indirect_unary_predicate<projected<I, Proj>> Pred>
bool any_of(Ep&& exec,
I first,
S last,
Pred pred,
Proj proj = {}); // (3) C++26

template <execution-policy Ep,
sized-random-access-range R,
class Proj = identity,
indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred>
bool any_of(Ep&& exec,
R&& r,
Pred pred,
Proj proj = {}); // (4) C++26
}
```
* execution-policy[link /reference/execution/execution-policy.md]
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* sized_sentinel_for[link /reference/iterator/sized_sentinel_for.md]
* sized-random-access-range[link /reference/ranges/sized-random-access-range.md]

## 概要
範囲のいずれかの要素が条件を満たすかを判定する。

- (1): イテレータ範囲を指定する
- (2): Rangeを直接指定する
- (3): (1)の並列アルゴリズム版。実行ポリシーを指定する
- (4): (2)の並列アルゴリズム版。実行ポリシーを指定する

## テンプレートパラメータ制約
- (1):
Expand All @@ -45,6 +71,7 @@ namespace std::ranges {
最大で `last - first` 回 `pred` を実行する。

## 例
### 基本的な使い方
```cpp example
#include <algorithm>
#include <iostream>
Expand All @@ -66,12 +93,37 @@ int main() {
```
* std::ranges::any_of[color ff0000]

### 出力
#### 出力
```
false
true
```

### 並列アルゴリズムの例 (C++26)
```cpp example
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>

int main() {
std::vector<int> v = {1, 3, 5, 7, 8};

std::cout << std::boolalpha;

// 並列にいずれかの要素が偶数であるかを判定
bool result = std::ranges::any_of(std::execution::par, v,
[](int x) { return x % 2 == 0; });
std::cout << result << std::endl;
}
```
* std::ranges::any_of[color ff0000]

#### 出力
```
true
```

## 実装例
```cpp
struct any_of_impl {
Expand Down Expand Up @@ -114,3 +166,4 @@ inline constexpr any_of_impl any_of;

## 参照
- [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms)
- [P3179R9 C++ parallel range algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3179r9.html)
63 changes: 63 additions & 0 deletions reference/algorithm/ranges_contains.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,52 @@ namespace std::ranges {
contains(R&& r,
const T& value,
Proj proj = {}); // (2) C++26

template <execution-policy Ep,
random_access_iterator I,
sized_sentinel_for<I> S,
class Proj = identity,
class T = projected_value_t<I, Proj>>
requires indirect_binary_predicate<
ranges::equal_to,
projected<I, Proj>,
const T*
>
bool
contains(Ep&& exec,
I first,
S last,
const T& value,
Proj proj = {}); // (3) C++26

template <execution-policy Ep,
sized-random-access-range R,
class Proj = identity,
class T = projected_value_t<iterator_t<R>, Proj>>
requires indirect_binary_predicate<
ranges::equal_to,
projected<iterator_t<R>, Proj>,
const T*
>
bool
contains(Ep&& exec,
R&& r,
const T& value,
Proj proj = {}); // (4) C++26
}
```
* execution-policy[link /reference/execution/execution-policy.md]
* random_access_iterator[link /reference/iterator/random_access_iterator.md]
* sized_sentinel_for[link /reference/iterator/sized_sentinel_for.md]
* sized-random-access-range[link /reference/ranges/sized-random-access-range.md]

## 概要
指定された値が含まれるか調べる。

- (1): イテレータ範囲を指定する
- (2): Rangeを直接指定する
- (3): (1)の並列アルゴリズム版。実行ポリシーを指定する
- (4): (2)の並列アルゴリズム版。実行ポリシーを指定する


## 戻り値
Expand Down Expand Up @@ -148,6 +186,30 @@ found
```


### 並列アルゴリズムの例 (C++26)
```cpp example
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>

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

std::cout << std::boolalpha;

// 並列に値が含まれるかを判定
bool result = std::ranges::contains(std::execution::par, v, 4);
std::cout << result << std::endl;
}
```
* std::ranges::contains[color ff0000]

#### 出力
```
true
```

## 実装例
```cpp
struct contains_impl {
Expand Down Expand Up @@ -182,3 +244,4 @@ inline constexpr contains_impl contains;
- [N4950 27 Algorithms library](https://timsong-cpp.github.io/cppwp/n4950/algorithms)
- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html)
- C++26で波カッコ初期化 (リスト初期化) に対応した
- [P3179R9 C++ parallel range algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3179r9.html)
Loading