> I have not understood what you mean saying about relation composition. Could
> you show how is_sorted can be used to check strictl ordering such a way that
> the comparison function will not contradict the standard?
You make a good point, is_sorted requires a strict weak ordering, but
we want a more general function that simply requires a relation to
validate. I believe that we can already construct such a function
indirectly via adjacent_find. If a sequence is strictly ordered given
some binary relation (e.g. <), then adjacent_find will always reach
the end of the sequence, if the used predicate is the negation of
original one. In other words: This is finding the first mismatch of
adjacent elements given the provided relation.
With the currently limited std::not2 composition we can write this as:
std::adjacent_find(begin, end, std::not2(std::less<X>{})) == end
But assuming we can use the more powerful negator not_fn,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3699.html
this should also be possible via the generic std::less<void>{} predicate:
std::adjacent_find(begin, end, std::not_fn(std::less<void>{})) == end
I tend to agree that we would like to have an algorithm, e.g.
is_relation_preserving, that hides the semantics of above test. Given
is_relation_preserving applied to some weak ordering r, your strict
ordering can be found by exactly this is_relation_preserving function,
while the non-strict form results by applying it again to the
complement of the converse of the relation.
But instead of inventing new algorithms, we could also consider
whether is_sorted really requires strict weak ordering. It currently
does so, because we have added it to [alg.sorting] imposing this
requirement, but that restriction might not be needed.
The standard itself never uses strict ordering, this is the reason why
I currently hesitate to add such a function. But it should be easy to
realize that intention. The currently blessed approach is based on
adjacent_find and the complement (negation) of the relation as shown
above.
- Daniel
> среда, 9 октября 2013 г., 23:02:52 UTC+4 пользователь Daniel Krügler
> написал:
>>
>> 2013/10/9 Vlad from Moscow <
vlad....@mail.ru>:
>> > So it seems that we need one more function that will be named for
>> > example as
>> > std::is_strictly_sorted.
>>
>> I disagree that there is need for this function in the standard, just
>> use relation composition. Albeit it might be useful to consider
>> relation adaptors for complement and converse. We have one of the
>> (not2), but not the other.
>>
>> - Daniel
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
std-discussio...@isocpp.org.
> To post to this group, send email to
std-dis...@isocpp.org.
> Visit this group at
>
http://groups.google.com/a/isocpp.org/group/std-discussion/.