Home > Net >  How to use std::views::transform on a vector?
How to use std::views::transform on a vector?

Time:06-23

I'm trying to create a view into a vector that transforms the type. From the doc I'd read that the following should work, but the compiler output is very confusing. What am I missing?

#include <ranges>
#include <vector>

int main() {
    std::vector<int> v {1, 2, 3};
    auto view = v | std::views::transform([](int i){ return std::to_string(i); });
}

Compiler output:

In file included from <source>:1:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:43:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/iterator:61:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/stl_iterator_base_types.h:71:
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:980:13: error: no matching function for call to '__begin'
        = decltype(ranges::__cust_access::__begin(std::declval<_Tp&>()));
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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>;
    ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_util.h:98:43: note: in instantiation of template type alias 'iterator_t' requested here
      data() requires contiguous_iterator<iterator_t<_Derived>>
                                          ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1013:29: note: in instantiation of template class 'std::ranges::view_interface<std::ranges::ref_view<std::vector<int>>>' requested here
    class ref_view : public view_interface<ref_view<_Range>>
                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of template class 'std::ranges::ref_view<std::vector<int>>' requested here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of requirement here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069: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>()}; };
                                 ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:747:9: note: while substituting template arguments into constraint expression here
      = requires { std::declval<_Adaptor>()(declval<_Args>()...); };
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while checking the satisfaction of concept '__adaptor_invocable<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while substituting template arguments into constraint expression here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:19: note: while checking constraint satisfaction for template 'operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' required here
    auto view = v | std::views::transform([](int i){ return std::to_string(i); });
                  ^
<source>:6:19: note: in instantiation of function template specialization 'std::ranges::views::__adaptor::operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:964:7: note: candidate template ignored: constraints not satisfied [with _Tp = std::ranges::ref_view<std::vector<int>>]
      __begin(_Tp& __t)
      ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:962:16: note: because 'is_array_v<std::ranges::ref_view<std::vector<int> > >' evaluated to false
      requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&>
               ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:962:35: note: and 'std::ranges::ref_view<std::vector<int>> &' does not satisfy '__member_begin'
      requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&>
                                  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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::vector<int>>'
          { __decay_copy(__t.begin()) } -> input_or_output_iterator;
                             ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:962:59: note: and 'std::ranges::ref_view<std::vector<int>> &' does not satisfy '__adl_begin'
      requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&>
                                                          ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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;
                         ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:980:13: error: no matching function for call to '__begin'
        = decltype(ranges::__cust_access::__begin(std::declval<_Tp&>()));
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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>;
    ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_util.h:104:25: note: in instantiation of template type alias 'iterator_t' requested here
        && contiguous_iterator<iterator_t<const _Derived>>
                               ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1013:29: note: in instantiation of template class 'std::ranges::view_interface<std::ranges::ref_view<std::vector<int>>>' requested here
    class ref_view : public view_interface<ref_view<_Range>>
                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of template class 'std::ranges::ref_view<std::vector<int>>' requested here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of requirement here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069: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>()}; };
                                 ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:747:9: note: while substituting template arguments into constraint expression here
      = requires { std::declval<_Adaptor>()(declval<_Args>()...); };
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while checking the satisfaction of concept '__adaptor_invocable<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while substituting template arguments into constraint expression here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:19: note: while checking constraint satisfaction for template 'operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' required here
    auto view = v | std::views::transform([](int i){ return std::to_string(i); });
                  ^
<source>:6:19: note: in instantiation of function template specialization 'std::ranges::views::__adaptor::operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:964:7: note: candidate template ignored: constraints not satisfied [with _Tp = const std::ranges::ref_view<std::vector<int>>]
      __begin(_Tp& __t)
      ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:962:16: note: because 'is_array_v<const std::ranges::ref_view<std::vector<int> > >' evaluated to false
      requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&>
               ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:962:35: note: and 'const std::ranges::ref_view<std::vector<int>> &' does not satisfy '__member_begin'
      requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&>
                                  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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::vector<int>>'
          { __decay_copy(__t.begin()) } -> input_or_output_iterator;
                             ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:962:59: note: and 'const std::ranges::ref_view<std::vector<int>> &' does not satisfy '__adl_begin'
      requires is_array_v<_Tp> || __member_begin<_Tp&> || __adl_begin<_Tp&>
                                                          ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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;
                         ^
In file included from <source>:1:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:46:
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_util.h:110:24: error: constraints not satisfied for alias template 'sentinel_t' [with _Range = std::ranges::ref_view<std::vector<int>>]
        && sized_sentinel_for<sentinel_t<_Derived>, iterator_t<_Derived>>
                              ^~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1013:29: note: in instantiation of template class 'std::ranges::view_interface<std::ranges::ref_view<std::vector<int>>>' requested here
    class ref_view : public view_interface<ref_view<_Range>>
                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of template class 'std::ranges::ref_view<std::vector<int>>' requested here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of requirement here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:27: note: while substituting template arguments into constraint expression here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1079:7: note: while checking the satisfaction of concept '__can_ref_view<std::vector<int> &>' requested here
          || __detail::__can_ref_view<_Range>
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1079:17: note: (skipping 18 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
          || __detail::__can_ref_view<_Range>
                       ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:747:9: note: while substituting template arguments into constraint expression here
      = requires { std::declval<_Adaptor>()(declval<_Args>()...); };
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while checking the satisfaction of concept '__adaptor_invocable<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while substituting template arguments into constraint expression here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:19: note: while checking constraint satisfaction for template 'operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' required here
    auto view = v | std::views::transform([](int i){ return std::to_string(i); });
                  ^
<source>:6:19: note: in instantiation of function template specialization 'std::ranges::views::__adaptor::operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_base.h:588:12: note: because 'std::ranges::ref_view<std::vector<int>>' does not satisfy 'range'
  template<range _Range>
           ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_base.h:576:2: note: because 'ranges::begin(__t)' would be invalid: no matching function for call to object of type 'const __cust_access::_Begin'
        ranges::begin(__t);
        ^
In file included from <source>:1:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:46:
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_util.h:116:24: error: constraints not satisfied for alias template 'sentinel_t' [with _Range = const std::ranges::ref_view<std::vector<int>>]
        && sized_sentinel_for<sentinel_t<const _Derived>,
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_base.h:588:12: note: because 'const std::ranges::ref_view<std::vector<int>>' does not satisfy 'range'
  template<range _Range>
           ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_base.h:576:2: note: because 'ranges::begin(__t)' would be invalid: no matching function for call to object of type 'const __cust_access::_Begin'
        ranges::begin(__t);
        ^
<source>:6:19: error: invalid operands to binary expression ('std::vector<int>' and '_Partial<std::ranges::views::_Transform, decay_t<(lambda at <source>:6:43)>>' (aka '_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>'))
    auto view = v | std::views::transform([](int i){ return std::to_string(i); });
                ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ios_base.h:87:3: note: candidate function not viable: no known conversion from 'std::vector<int>' to 'std::_Ios_Fmtflags' for 1st argument
  operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ios_base.h:129:3: note: candidate function not viable: no known conversion from 'std::vector<int>' to 'std::_Ios_Openmode' for 1st argument
  operator|(_Ios_Openmode __a, _Ios_Openmode __b)
  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ios_base.h:169:3: note: candidate function not viable: no known conversion from 'std::vector<int>' to 'std::_Ios_Iostate' for 1st argument
  operator|(_Ios_Iostate __a, _Ios_Iostate __b)
  ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:774:7: note: candidate template ignored: constraints not satisfied [with _Self = std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, _Range = std::vector<int> &]
      operator|(_Range&& __r, _Self&& __self)
      ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: because '__adaptor_invocable<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' evaluated to false
        && __adaptor_invocable<_Self, _Range>
           ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:747:20: note: because 'std::declval<_Adaptor>()(declval<_Args>()...)' would be invalid: no matching function for call to object of type 'std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>'
      = requires { std::declval<_Adaptor>()(declval<_Args>()...); };
                   ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:783:7: note: candidate template ignored: constraints not satisfied [with _Lhs = std::vector<int>, _Rhs = std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>]
      operator|(_Lhs __lhs, _Rhs __rhs)
      ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:780:16: note: because 'derived_from<std::vector<int>, std::ranges::views::__adaptor::_RangeAdaptorClosure>' evaluated to false
      requires derived_from<_Lhs, _RangeAdaptorClosure>
               ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/concepts:67:28: note: because '__is_base_of(std::ranges::views::__adaptor::_RangeAdaptorClosure, std::vector<int>)' evaluated to false
    concept derived_from = __is_base_of(_Base, _Derived)
                           ^
5 errors generated.
ASM generation compiler returned: 1
In file included from <source>:1:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:43:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/iterator:61:
In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/stl_iterator_base_types.h:71:
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/iterator_concepts.h:980:13: error: no matching function for call to '__begin'
        = decltype(ranges::__cust_access::__begin(std::declval<_Tp&>()));
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/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>;
    ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/bits/ranges_util.h:98:43: note: in instantiation of template type alias 'iterator_t' requested here
      data() requires contiguous_iterator<iterator_t<_Derived>>
                                          ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1013:29: note: in instantiation of template class 'std::ranges::view_interface<std::ranges::ref_view<std::vector<int>>>' requested here
    class ref_view : public view_interface<ref_view<_Range>>
                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of template class 'std::ranges::ref_view<std::vector<int>>' requested here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069:38: note: in instantiation of requirement here
        concept __can_ref_view = requires { ref_view{std::declval<_Range>()}; };
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:1069: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>()}; };
                                 ^
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:747:9: note: while substituting template arguments into constraint expression here
      = requires { std::declval<_Adaptor>()(declval<_Args>()...); };
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while checking the satisfaction of concept '__adaptor_invocable<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/../../../../include/c  /11.2.0/ranges:772:5: note: while substituting template arguments into constraint expression here
        && __adaptor_invocable<_Self, _Range>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:19: note: while checking constraint satisfaction for template 'operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' required here
    auto view = v | std::views::transform([](int i){ return std::to_string(i); });
                  ^
<source>:6:19: note: in instantiation of function template specialization 'std::ranges::views::__adaptor::operator|<std::ranges::views::__adaptor::_Partial<std::ranges::views::_Transform, (lambda at <source>:6:43)>, std::vector<int> &>' requested here

[...]

CodePudding user response:

This is a known bug in Clang's concepts implementation, see https://github.com/llvm/llvm-project/issues/44178

The change https://reviews.llvm.org/D119544 is supposed to fix it, but it hasn't been committed to Clang trunk yet (as of June 22 2022).

  • Related