- ranges[meta header]
- std::ranges[meta namespace]
- class template[meta id-type]
- cpp23[meta cpp]
namespace std::ranges {
template<forward_range V, move_constructible F, size_t N>
requires view<V> && (N > 0) && is_object_v<F> &&
regular_invocable<F&, REPEAT(range_reference_t<V>, N)...> &&
can-reference<invoke_result_t<F&, REPEAT(range_reference_t<V>, N)...>>
class adjacent_transform_view : public view_interface<adjacent_transform_view<V, F, N>> { …… }; // (1)
namespace views {
inline constexpr /*unspecified*/ adjacent_transform = /*unspecified*/; // (2)
}
}- REPEAT[italic]
- can-reference[link /reference/iterator/dereferenceable.md]
adjacent_transform_viewは各要素とそれに隣接する要素をコンパイル時指定の個数ずつ取り出し、それらを引数として関数を呼び出した結果を要素とするview。
adjacent_transform_viewの要素を1つ取得するごとに、V の要素を N 個取得する。
N が元となるRangeの要素数より大きい場合、このviewは空である。
- (1):
adjacent_transform_viewのクラス定義 - (2):
adjacent_transform_viewを生成するカスタマイゼーションポイントオブジェクト
| borrowed | sized | output | input | forward | bidirectional | random_access | contiguous | common | viewable | view |
|---|---|---|---|---|---|---|---|---|---|---|
| (1) | 〇 | 〇 | (1) | (1) | (1) | (1) | ○ | ○ |
- (1):
adjacent_view<V, N>に従う
- (2): 式
views::adjacent_transform<N>(E, F)の効果は以下の通り。N> 0 のとき、adjacent_transform_view<views::all_t<decltype((E))>,decay_t<decltype((F))>, N>(E, F)と等しいN= 0 のとき、((void)E,views::zip_transform(F))と等しい(ただしEとFの評価順は不定)
REPEAT(T, N) をT型のN個のパックとする。
| 名前 | 説明 | 対応バージョン |
|---|---|---|
(constructor) |
コンストラクタ | C++23 |
base |
Vの参照を取得する |
C++23 |
begin |
先頭を指すイテレータを取得する | C++23 |
end |
番兵を取得する | C++23 |
size |
要素数を取得する | C++23 |
| 名前 | 説明 | 対応バージョン |
|---|---|---|
empty |
Rangeが空かどうかを判定する | C++23 |
operator bool |
Rangeが空でないかどうかを判定する | C++23 |
front |
先頭要素への参照を取得する | C++23 |
back |
末尾要素への参照を取得する | C++23 |
cbegin |
定数イテレータを取得する | C++23 |
cend |
定数イテレータ(番兵)を取得する | C++23 |
operator[] |
要素へアクセスする | C++23 |
| 名前 | 説明 | 対応バージョン |
|---|---|---|
(deduction_guide) |
クラステンプレートの推論補助 | C++23 |
#include <iostream>
#include <vector>
#include <ranges>
int main() {
// 隣接する要素間の差を計算する
std::vector v = {9, 2, 5, 3, 6, 7};
for (int x : v | std::views::adjacent_transform<2>(
[](auto x, auto y) { return y - x; })) {
std::cout << x << std::endl;
}
}- std::views::adjacent_transform[color ff0000]
-7
3
-2
3
1
- C++23
- Clang: 20 [mark noimpl]
- GCC: 15 [mark noimpl]
- Visual C++: 2022 Update 14 [mark noimpl]
std::adjacent_difference- 隣接する2つの要素間の差を計算するアルゴリズム関数