C++ Logo

std-proposals

Advanced search

[std-proposals] std::ranges::equal(v, {1,2,3,4,5})

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Tue, 24 Jan 2023 11:59:25 -0500
Hi Giuseppe, std-proposals,

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2248r7.html
I just noticed today that P2248 "Enabling list-initialization for
algorithms" still fails to enable this very common use-case of mine:
    std::vector<int> v = {1,2,3,4,5};
    assert(std::ranges::equal(v, {1,2,3,4,5}));
Was this possibility ever discussed before?
This *could* be handled by defaulting the `R2` parameter to
`initializer_list`, but it probably makes more sense to add a whole new
overload of `std::equal`, as follows. (This means it's quite reasonable
that P2248 wouldn't have proposed this idea... but I'm still wondering if
it's been discussed before.)

// the existing overload
template<ranges::input_range
<http://en.cppreference.com/w/cpp/ranges/input_range> R1, ranges::
input_range <http://en.cppreference.com/w/cpp/ranges/input_range> R2,

         class Pred = ranges::equal_to
<http://en.cppreference.com/w/cpp/utility/functional/ranges/equal_to>,
         class Proj1 = std::identity
<http://en.cppreference.com/w/cpp/utility/functional/identity>, class Proj2
= std::identity
<http://en.cppreference.com/w/cpp/utility/functional/identity>>
  requires std::indirectly_comparable
<http://en.cppreference.com/w/cpp/iterator/indirectly_comparable><ranges::
iterator_t <http://en.cppreference.com/w/cpp/ranges/iterator_t><R1>,
ranges::iterator_t <http://en.cppreference.com/w/cpp/ranges/iterator_t><R2>,
                                      Pred, Proj1, Proj2>
constexpr bool equal( R1&& r1, R2&& r2, Pred pred = {},
                      Proj1 proj1 = {}, Proj2 proj2 = {} );

// the new overload
template<ranges::input_range
<http://en.cppreference.com/w/cpp/ranges/input_range> R1, *class V2,*

         class Pred = ranges::equal_to
<http://en.cppreference.com/w/cpp/utility/functional/ranges/equal_to>,
         class Proj1 = std::identity
<http://en.cppreference.com/w/cpp/utility/functional/identity>, class Proj2
= std::identity
<http://en.cppreference.com/w/cpp/utility/functional/identity>>
  requires std::indirectly_comparable
<http://en.cppreference.com/w/cpp/iterator/indirectly_comparable><ranges::
iterator_t <http://en.cppreference.com/w/cpp/ranges/iterator_t><R1>, *const
V2**,
                                      Pred, Proj1, Proj2>
constexpr bool equal( R1&& r1, *std::initializer_list<V2>* r2, Pred pred = {
},
                      Proj1 proj1 = {}, Proj2 proj2 = {} );

–Arthur

Received on 2023-01-24 16:59:38