Closed JeffGarland closed 5 years ago
Additional information. filter_view exhibits the same compile error -- needs an explicit injection of ref_view to compile a similar example.
confirmed that cmcstl2 works with my environment without the explicit ref_view for both filter_view and transform_view. Also realizing that in other code I have with join_view the ref_view over vector is implicitly generated. Not sure where the standard says to do that, but with extra data guessing this is a bug.
The difference is that in the Working Draft, the transform_view
has a deduction guide that makes it work.
template<class R, class F>
transform_view(R&&, F) -> transform_view<all_view<R>, F>;
Range-v3 hasn't gotten deduction guides yet.
I'm turning this into a feature request to add deduction guides when the compiler supports them.
From the post-kona working paper (N4810) I believe the following should be valid code. However it fails to compile unless an explicit ref_view is added to convert the vector to a view before applying transform (see successful option below which compiles and runs correctly). Same behavior on gcc8.3 and late march gcc trunk compile with -std=c++2a or c++17. The compile error here indicates ViewableRange while N4810 says the following:
template<InputRange V, CopyConstructible F> requires View && is_object_v &&
RegularInvocable<F&, iter_reference_t<iterator_t>>
class transform_view;
My understanding is that std::vector is not a view, so this compile error seems correct -- which would imply the example in range.transform.overview is not correct.
include <range/v3/all.hpp>
include
include
using std::cout, std::vector;
int main() { vector vi{ 0, 1, 2, 3, 4, 5 };
//successful option // ranges::transform_view times_ten{ranges::ref_view{vi}, [](int i) { return i 10; } }; ranges::transform_view times_ten{ vi, [](int i) { return i 10; } };
for (int i : times_ten) { cout << i << ' '; // 0 10 20 30 40 50 } cout << "\n"; }
-- mode: compilation; default-directory: "~/dev/cpp_experiment/cpp20/range/error/" -- Compilation started at Sat Mar 30 18:30:26
/home/jeff/devtools/gcc83/install/usr/local/bin/g++ 010_transform_view.cpp -I ~/devtools/range_v3_beta1/range-v3/include -std=c++2a In file included from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/iterator/concepts.hpp:20, from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/iterator/operations.hpp:19, from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/core.hpp:17, from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/all.hpp:17, from 010_transform_view.cpp:3: /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/adaptor.hpp: In instantiation of ‘struct ranges::view_adaptor<ranges::iter_transform_view<std::vector, ranges::indirected<main()::<lambda(int)> > >, std::vector, (ranges::cardinality)-1>’:
/home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/transform.hpp:94:12: required from ‘struct ranges::iter_transform_view<std::vector, ranges::indirected<main()::<lambda(int)> > >’
/home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/transform.hpp:180:12: required from ‘struct ranges::transform_view<std::vector, main()::<lambda(int)> >’
010_transform_view.cpp:17:70: required from here
/home/jeff/devtools/range_v3_beta1/range-v3/include/concepts/concepts.hpp:130:19: error: static assertion failed: Concept assertion failed : ViewableRange
static_assert(static_cast(__VA_ARGS__), \
^);
^ using all_t = decltype (ranges::view::all(declval())) [with Rng = std::vector]’:
/home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/adaptor.hpp:414:50: required from ‘struct ranges::view_adaptor<ranges::iter_transform_view<std::vector, ranges::indirected<main()::<lambda(int)> > >, std::vector, (ranges::cardinality)-1>’
/home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/transform.hpp:94:12: required from ‘struct ranges::iter_transform_view<std::vector, ranges::indirected<main()::<lambda(int)> > >’
/home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/transform.hpp:180:12: required from ‘struct ranges::transform_view<std::vector, main()::<lambda(int)> >’
010_transform_view.cpp:17:70: required from here
/home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/all.hpp:86:35: error: no match for call to ‘(const ranges::view::all_fn) (std::vector)’
using all_t = decltype(all(std::declval()));
~~~~~~~~~ /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/adaptor.hpp:413:9: note: in expansion of macro ‘CPP_assert’ CPP_assert(ViewableRange~~~~~ In file included from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/adaptor.hpp:26, from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/core.hpp:23, from /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/all.hpp:17, from 010_transform_view.cpp:3: /home/jeff/devtools/range_v3_beta1/range-v3/include/range/v3/view/all.hpp: In substitution of ‘template