You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
17
22
18
23
Pillars: https://github.com/ericniebler/range-v3
19
24
Views - Views are composable adaptations of ranges where the adaptation happens lazily as the view is iterated.
20
25
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.
21
26
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/
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.
43
29
@@ -48,6 +34,9 @@ Views and actions use the pipe syntax (e.g., rng | adapt1 | adapt2 | ...) so you
Ranges (not Iterables) are copyable and assignable. They don't own the elements like, say, a container
50
36
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!
51
40
52
41
> what it is - anything you can iterate through (docs.microsoft.com when talking about range-based for)
53
42
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
73
62
std::vector<int> numbers = {1, 2, 3, 4, 5, 6};
74
63
auto results = numbers | std::views::filter([](int n){ return n % 2 == 0; })
75
64
| 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:
77
69
A range adaptor is an object that can be combined with a range in order to produce a new range.
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).
89
81
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
90
90
91
+
Views and actions use the pipe syntax (e.g., rng | adapt1 | adapt2 | ...) so your code is terse and readable from left to right.
0 commit comments