I have the following code where for some reason only last block does not work.
I originally thought it may be related to unique_ptr being move only or std::set having const keys, but then it is unclear why other blocks work.
namespace sr = std::ranges; namespace sv = std::views; int main() { { std::set<int> up_s{10,20}; const auto up_vec = sv::as_rvalue(up_s) | sr::to<std::vector>(); assert(up_vec.size() == 2); } { std::vector<std::unique_ptr<int>> up_d; up_d.emplace_back(std::make_unique<int>(10)); up_d.emplace_back(std::make_unique<int>(20)); const auto up_vec = sv::as_rvalue(up_d) | sr::to<std::vector>(); assert(up_vec.size() == 2); } { std::set<std::unique_ptr<int>> up_d; up_d.emplace(std::make_unique<int>(10)); up_d.emplace(std::make_unique<int>(20)); //const auto up_vec = sv::as_rvalue(up_d) | sr::to<std::vector>(); //assert(up_vec.size() == 2); } } Error message seems useless, as it looks like that for some reason code wants to treat unique_ptr as range
/opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/ranges:9354:25: error: static assertion failed 9354 | static_assert(input_range<range_reference_t<_Rg>>); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/ranges:9354:25: note: constraints not satisfied
...
/opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/bits/ranges_base.h:499:13: required for the satisfaction of 'range<_Tp>' [with _Tp = const std::unique_ptr<int, std::default_delete >&&] /opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/bits/ranges_base.h:499:21: in requirements with '_Tp& __t' [with _Tp = const std::unique_ptr<int, std::default_delete >&&] /opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/bits/ranges_base.h:501:22: note: the required expression 'std::ranges::_Cpo::begin(__t)' is invalid 501 | ranges::begin(__t); | ~~~~~~~~~~~~~^~~~~ /opt/compiler-explorer/gcc-trunk-20240513/include/c++/15.0.0/bits/ranges_base.h:502:20: note: the required expression 'std::ranges::_Cpo::end(__t)' is invalid 502 | ranges::end(__t);