In the proposed C++20 (The One) Ranges TS, what is the proposed method for converting the view into a std::vector?
The following code does not compile:
int
main() {
std::vector<float> values = {1.0, 2.0, 3.0, 4.0, 5.2, 6.0, 7.0, 8.0, 9.0};
//fmt::print("{}\n", std::experimental::ranges::views::filter(values, [] (float v) { return v < 5.f; }));
std::vector<float> foo = vw::filter(values, [] (float v) { return v < 5.f; });
fmt::print("{}\n", foo);
}
with the error
../src/view.cpp:19:40: error: conversion from ‘std::experimental::ranges::v1::filter_view<std::experimental::ranges::v1::ref_view<std::vector<float> >, main()::<lambda(float)> >’ to non-scalar type ‘std::vector<float>’ requested
std::vector<float> foo = vw::filter(values, [] (float v) { return v < 5.f; });
(the commented line will also not compile due to some CV constraints).
So how do I do anything with a view except for using a range-based for loop?
Also some bonus questions:
- Is the cmcstl2 implementation I used even following the proposal? The ranges-v3 seems not to be.
- Is there any documentation on the Ranges TS? The proposal PDF I found is pretty much an awfully formatted code dump in diff style. In fact directly reading the cmcstl2 sources was way easier to read for me. The cppreference seems to be lacking as well...
copy
? It has new definitions in C++20: eel.is/c++draft/alg.copy – Maxie|
operator to apply views on ranges. – Peasleeto_vector
. E.g.: github.com/ericniebler/range-v3/blob/master/test/range/… of course I'm not sure what was finally standardised... – Eyeglass