ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 441 forks source link

the `ranges::view_` concept diverged from the standand #1662

Open huixie90 opened 3 years ago

huixie90 commented 3 years ago

ranges::view_ requires semiregular but std::ranges::view only requires movable. std doesn't require copyable or default constructible. Is there a plan to make range-v3 consistent with std::range ?

marehr commented 2 years ago

This has the effect, that you can't combine g++-12 views with range-v3 views any more.

But this has more implications to the underlying range-v3 implementation, as some views expect default_initializable.

slymz commented 2 years ago

But this has more implications to the underlying range-v3 implementation, as some views expect default_initializable.

can you an example or two? also it should be ok for a view to be default_initializable (most are I suppose). it just shouldn't be required for all views.

marehr commented 2 years ago

std::views::ref_view does not have a default constructor.

That means the basic building block std::views::all isn't combinable with any range-v3 view.

#include <ranges>
#include <vector>

#include <range/v3/range/concepts.hpp>

namespace ranges
{
//!\brief std::ranges::views are valid range-v3 views
template<::std::derived_from<::std::ranges::view_base> T>
inline constexpr bool enable_view<T> = true;
}

namespace std::ranges
{
//!\brief range-v3 views are valid std::ranges::views
template<class T>
    requires ::std::derived_from<T, ::ranges::view_base>
inline constexpr bool enable_view<T> = true;
}

int main()
{
    std::vector<int> numbers{};
    auto view = std::views::all(numbers);

    static_assert(std::ranges::view<decltype(view)>);

    // ranges::cpp20::view<decltype(view)> requires
    /*1.)*/ static_assert(ranges::range<decltype(view)>); // true
    /*2.)*/ static_assert(ranges::semiregular<decltype(view)>); // false
    /*3.)*/ static_assert(ranges::enable_view<decltype(view)>); // true

    static_assert(ranges::cpp20::view<decltype(view)>); // false

    return 0;
}

https://godbolt.org/z/58o4sc4TP

(Independent of the current ICE)

marehr commented 2 years ago

But I guess dropping semiregular in favour of copyable would be a good first step for range-v3, as most views of range-v3 should work with non-default initializable views.

https://github.com/ericniebler/range-v3/pull/1652 did a similar thing for weakly_incrementable (relaxing it from semiregular to copyable).

slymz commented 2 years ago

I guess dropping semiregular in favour of copyable would be a good first step

Putting the relevant proposals here for reference:

These are both in C++20 for good reasons. range-v3 should follow suit without beating around the bush.

JohelEGP commented 2 years ago

I remember Eric mentioning recently that just modifying the concepts isn't enough as there is code that make assumptions as to what the concepts require.