fixed example code: -- #include <algorithm> #include <cstdio> #include <ranges> #include <string>
char rot13a(const char x, const char a) { return a + (((x - a) + 13) % 26); } char rot13(const char x) { if (x >= 'A' && x <= 'Z') { return rot13a(x, 'A'); } if (x >= 'a' && x <= 'z') { return rot13a(x, 'a'); } return x; } int main() { auto show = [](const char x) { std::putchar(x); }; std::string in{ "cppreference.com\n" }; std::ranges::for_each(in, show); std::ranges::for_each(in | std::views::transform(rot13), show); std::string out; std::ranges::copy( std::views::transform(in, rot13), std::back_inserter(out) ); std::ranges::for_each(out, show); std::ranges::for_each(out | std::views::transform(rot13), show); } errors: -- In file included from tmp.cpp:1: In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/algorithm:61: In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algobase.h:65: In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_iterator_base_types.h:71: /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:980:13: fatal error: no matching function for call to '__begin' = decltype(ranges::__cust_access::__begin(std::declval<_Tp&>())); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/ranges_base.h:586:5: note: in instantiation of template type alias '__range_iter_t' requested here using iterator_t = std::__detail::__range_iter_t<_Tp>; ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/ranges_util.h:98:43: note: in instantiation of template type alias 'iterator_t' requested here data() requires contiguous_iterator<iterator_t<_Derived>> ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:1014:29: note: in instantiation of template class 'std::ranges::view_interface<std::ranges::ref_view<std::basic_string<char>>>' requested here class ref_view : public view_interface<ref_view<_Range>> ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:1070:38: note: in instantiation of template class 'std::ranges::ref_view<std::basic_string<char>>' requested here concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; }; ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:1070:38: note: in instantiation of requirement here concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; }; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:1070:27: note: (skipping 20 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; }; ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:748:9: note: while substituting template arguments into constraint expression here = requires { std::declval<_Adaptor>()(declval<_Args>()...); }; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:773:5: note: while checking the satisfaction of concept '__adaptor_invocable<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, char (*)(char)>, std::basic_string<char> &>' requested here && __adaptor_invocable<_Self, _Range> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ranges:773:5: note: while substituting template arguments into constraint expression here && __adaptor_invocable<_Self, _Range> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tmp.cpp:30:30: note: while checking constraint satisfaction for template 'operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, char (*)(char)>, std::basic_string<char> &>' required here std::ranges::for_each(in | std::views::transform(rot13), show); ^ tmp.cpp:30:30: note: in instantiation of function template specialization 'std::ranges::views::__adaptor::operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, char (*)(char)>, std::basic_string<char> &>' requested here /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:964:7: note: candidate template ignored: constraints not satisfied [with _Tp = std::ranges::ref_view<std::basic_string<char>>] __begin(_Tp& __t) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:962:16: note: because 'is_array_v<std::ranges::ref_view<std::basic_string<char> > >' evaluated to false requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&> ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:962:35: note: and 'std::ranges::ref_view<std::basic_string<char>> &' does not satisfy '__member_begin' requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&> ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:945:23: note: because '__decay_copy(__t.begin())' would be invalid: no member named 'begin' in 'std::ranges::ref_view<std::basic_string<char>>' { __decay_copy(__t.begin()) } -> input_or_output_iterator; ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:962:59: note: and 'std::ranges::ref_view<std::basic_string<char>> &' does not satisfy '__adl_begin' requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&> ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/iterator_concepts.h:956:19: note: because '__decay_copy(begin(__t))' would be invalid: call to deleted function 'begin' { __decay_copy(begin(__t)) } -> input_or_output_iterator; ^ 1 error generated. shell returned 1