Skip to content

Commit deb7b62

Browse files
TylerMSFTTylerMSFT
authored andcommitted
draft
1 parent 03eb188 commit deb7b62

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

docs/standard-library/ranges.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,24 @@ f1_keywords: ["<ranges>"]
66
helpviewer_keywords: ["ranges header"]
77
---
88

9+
10+
Range algorithms available (casey list):
11+
https://devblogs.microsoft.com/cppblog/initial-support-for-c20-ranges/
12+
13+
14+
# `<ranges>`
15+
16+
## INTRO
17+
918
introduction - what is a range
1019
motivations/advantages
1120
example
1221

13-
It’s been 20 years since the STL was standardized, and all I want to do is pass a vector to sort. Is that too much to ask? Nope. With C++20, you will finally be able to do this: https://ericniebler.com/2018/12/05/standard-ranges/
14-
15-
std::vector< int > v = // ...
16-
std::ranges::sort( v ); // Hurray!
1722

1823
Pillars: https://github.com/ericniebler/range-v3
1924
Views - Views are composable adaptations of ranges where the adaptation happens lazily as the view is iterated.
2025
Actions - an action is an eager application of an algorithm to a container that mutates the container in-place and returns it for further processing.
2126
Algorithms
22-
23-
range adaptors : https://ericniebler.com/2018/12/05/standard-ranges/
24-
example
25-
Also The true power of ranges lies in the ability to create pipelines that transform ranges on the fly https://ericniebler.com/2018/12/05/standard-ranges/
26-
but these may be out of date - verify in product
27-
view adaptors
28-
https://www.fluentcpp.com/2017/01/12/ranges-stl-to-the-next-level/ (good range/view examples, composability)
29-
example
30-
31-
Views and actions use the pipe syntax (e.g., rng | adapt1 | adapt2 | ...) so your code is terse and readable from left to right.
32-
33-
Range algorithms available (casey list):
34-
https://devblogs.microsoft.com/cppblog/initial-support-for-c20-ranges/
35-
36-
37-
# `<ranges>`
38-
39-
INTRO:
40-
4127
From eric niebler
4228
Ranges are an extension of the Standard Template Library that makes its iterators and algorithms more powerful by making them composable. Unlike other range-like solutions which seek to do away with iterators, in range-v3 ranges are an abstration layer on top of iterators.
4329

@@ -48,6 +34,9 @@ Views and actions use the pipe syntax (e.g., rng | adapt1 | adapt2 | ...) so you
4834
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4128.html#design-goals
4935
Ranges (not Iterables) are copyable and assignable. They don't own the elements like, say, a container
5036

37+
It’s been 20 years since the STL was standardized, and all I want to do is pass a vector to sort. Is that too much to ask? Nope. With C++20, you will finally be able to do this: https://ericniebler.com/2018/12/05/standard-ranges/
38+
std::vector< int > v = // ...
39+
std::ranges::sort( v ); // Hurray!
5140

5241
> what it is - anything you can iterate through (docs.microsoft.com when talking about range-based for)
5342
Essentially, a range is something that can be traversed. More precisely, a range is something that has a begin() and an end() method, that return objects (iterators) that let you iterate over the range (that is, move along the elements of the range, and be dereferenced to access these elements). - https://www.fluentcpp.com/2017/01/12/ranges-stl-to-the-next-level/
@@ -73,7 +62,10 @@ Such algorithms reuse the STL versions in their implementation, by forwarding th
7362
std::vector<int> numbers = {1, 2, 3, 4, 5, 6};
7463
auto results = numbers | std::views::filter([](int n){ return n % 2 == 0; })
7564
| std::views::transform([](int n){ return n * 2; });
76-
> What is a range adaptor:
65+
66+
## range adaptor
67+
68+
What is a range adaptor:
7769
A range adaptor is an object that can be combined with a range in order to produce a new range.
7870
https://www.fluentcpp.com/2017/01/12/ranges-stl-to-the-next-level/
7971
With the following collection of numbers:
@@ -87,7 +79,20 @@ A range adaptor is an object that can be combined with a range in order to produ
8779
ranges::accumulate(numbers | view::transform(multiplyBy2), 0);
8880
returns 1*2 + 2*2 + 3*2 + 4*2 + 5*2 = 30 (similarly to std::accumulate, ranges::accumulate does the sum of the elements of the range it is passed to).
8981

82+
range adaptors : https://ericniebler.com/2018/12/05/standard-ranges/
83+
example
84+
Also The true power of ranges lies in the ability to create pipelines that transform ranges on the fly https://ericniebler.com/2018/12/05/standard-ranges/
85+
but these may be out of date - verify in product
86+
87+
88+
89+
## Views
9090

91+
Views and actions use the pipe syntax (e.g., rng | adapt1 | adapt2 | ...) so your code is terse and readable from left to right.
92+
93+
view adaptors
94+
https://www.fluentcpp.com/2017/01/12/ranges-stl-to-the-next-level/ (good range/view examples, composability)
95+
example
9196

9297
List of views: https://www.modernescpp.com/index.php/c-20-the-ranges-library
9398

0 commit comments

Comments
 (0)