Files
2025-10-25 03:02:53 +03:00

41 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[range.adaptors.general]
# 25 Ranges library [[ranges]](./#ranges)
## 25.7 Range adaptors [[range.adaptors]](range.adaptors#general)
### 25.7.1 General [range.adaptors.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4177)
Subclause [[range.adaptors]](range.adaptors "25.7Range adaptors") defines [*range adaptors*](#def:range_adaptors), which are utilities that transform a
range into a view with custom behaviors[.](#1.sentence-1)
These
adaptors can be chained to create pipelines of range transformations that
evaluate lazily as the resulting view is iterated[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4183)
Range adaptors are declared in namespace std::ranges::views[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4186)
The bitwise or operator is overloaded for the purpose of creating adaptor chain
pipelines[.](#3.sentence-1)
The adaptors also support function call syntax with equivalent
semantics[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4191)
[*Example [1](#example-1)*: vector<int> ints{0,1,2,3,4,5};auto even = [](int i) { return 0 == i % 2; };auto square = [](int i) { return i * i; };for (int i : ints | views::filter(even) | views::transform(square)) { cout << i << ' '; // prints 0 4 16} assert(ranges::equal(ints | views::filter(even), views::filter(ints, even))); — *end example*]