C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Introduction of std::is_uniqued()

From: LoS <aurumpuro_at_[hidden]>
Date: Fri, 14 Apr 2023 20:44:33 +0200
On Fri, Apr 14, 2023, 7:51 PM Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
wrote:

>
> I don't know about "needs," but we do use this primitive in the *invariant
> assertions* of flat_set and flat_map. So at least possibly "wants."
>
> https://github.com/Quuxplusone/llvm-project/blob/trivially-relocatable-v60/libcxx/include/__flat_set/flat_set.h#L1055-L1059
>
> The main motivation here IMHO is simple symmetry. Consider that we already
> have
> - is_sorted_until (returns iterator), is_sorted (i.e. is_sorted_until ==
> end())
> - is_heap_until (returns iterator), is_heap (i.e. is_heap_until == end())
> - adjacent_find (returns iterator), *???* (i.e. adjacent_find == end())
> - mismatch (returns iterators), equal (i.e. mismatch == {end(), end()})
> - find_if (returns iterator), none_of (i.e. find_if == end())
> - find (returns iterator), contains (i.e. find != end())
> - search (returns iterator), contains_subrange (i.e. search != end())
>
> The proposal simply fills this gap. Or at least it *should* simply fill
> it.
>
> @LoS: I'd be happy to coauthor if you like, and if you let me rewrite it
> in Bikeshed format. ;)
> (See my Bikeshed style in the latest proposals on this list:
> https://quuxplusone.github.io/draft/ )
>
> Right now the proposed specification is (1) too verbose, and (2) too
> constrictive — it doesn't actually allow for the one use-case presented
> above. (Instead it makes it quiet UB, which is awful. There's never a good
> reason to introduce gratuitous UB into an STL algorithm.)
> The right spec is no more or less than:
>
> Effects: Equivalent to: `return std::adjacent_find(first, last, pred)
> == last;`
>
> Compare:
> - https://eel.is/c++draft/alg.adjacent.find
> - https://eel.is/c++draft/is.sorted#1
> - https://eel.is/c++draft/alg.contains#1
>
> my $.02,
> Arthur
>

@Arthur, I let you rewrite the proposal in Bikeshed format :)
Sorry for my verbosity, but I am still a noob in writing proposals.

I post again the function signatures under the /* Ranges */ section,
because the concept std::equivalence_relation should be replaced with the
concept std::binary_predicate as used in std::adjacent_find().

template< std::forward_iterator I, std::sentinel_for<I> S, class Proj =
std::identity, std::indirect_binary_predicate <std::projected<I, Proj>,
std::projected<I, Proj>> Pred =
ranges::equal_to >
constexpr bool is_uniqued( I first, S last, Pred pred = {}, Proj proj = {}
);

template< ranges::forward_range R, class Proj = std::identity,
std::indirect_binary_predicate <std::projected<ranges::iterator_t<R>,
Proj>,
std::projected<ranges::iterator_t<R>, Proj>> Pred = ranges::equal_to>
constexpr bool is_uniqued( R&& r, Pred pred = {}, Proj proj = {} );

Regards,
LoS (Enrico Mauro)

>

Received on 2023-04-14 18:44:47