Date
2023-02-27.00:00:00
Message id
13439

Content

The requirements of viewable_range for view type is view<remove_cvref_t<T>> && constructible_from<remove_cvref_t<T>, T>, that is, when the decayed type of T models view, it must be constructible from T.

This part of the constraint corresponds to first bullet of views::all ([range.all.general]), which returns decay-copy(E) if the decayed type of E models view.

However, decay-copy(E) constraints convertible_to<T, decay_t<T>> which is a stronger requirement than constructible_from, which is reflected in its rejection of types with explicit copy constructors.

This inconsistency is such that the following causes the range adapter to produce a hard error when invoked (online example):

#include <ranges>

struct View : std::ranges::view_base 
{
  View();
  explicit View(const View&); // explicit copy constructor
  View& operator=(const View&);
  View(View&&);
  
  int* begin();
  int* end();
};

int main() 
{
  View v;
  auto r = std::views::take(v, 5); // hard error
}