Add irreflexive comparison debug check
François Dumont
frs.dumont@gmail.com
Fri Aug 21 19:30:00 GMT 2015
On 01/08/2015 02:25, Jonathan Wakely wrote:
> On 31 July 2015 at 20:49, François Dumont wrote:
>> On 30/07/2015 12:30, Jonathan Wakely wrote:
>>> On 29/07/15 22:08 +0200, François Dumont wrote:
>>>> Standard algos signatures are such that there is no guaranty that
>>>> the operator < or predicate to compare the iterator value type will
>>>> exist. So I had to check if the call is valid using C++11 features
>>>> declval and decltype.
>>> Surely if someone calls an algorithm that requires a
>>> StrictWeakOrdering then we know that it's valid to compare the value
>>> types using the comparison implied by that particular call (either
>>> operator< or the supplied predicate), and we should only be adding
>>> this assertion to algorithms that require a StrictWeakOrdering.
>>>
>>> Am I missing something?
>> If you consider for instance lower_bound signature:
>>
>> template<typename _ForwardIterator, typename _Tp>
>> inline _ForwardIterator
>> lower_bound(_ForwardIterator __first, _ForwardIterator __last,
>> const _Tp& __val)
>>
>> This algo require expressions *__first < __val or __val < *__first
>> to be well defined. But what the check is doing is *__first < *__first
>> that might not exist as the algo won't need it. The range [__first,
>> __last[ might have been sorted using another functor that we don't know
>> at the time of the call to lower_bound.
>>
>> There might be situations where the check will be useless but I
>> prefer to keep this debug check simple and so always go through the check.
> OK, but that is only true for some algos, it's not a problem for many
> of them, e.g. std::sort we know that we only ever do homogeneous
> comparisons, so we don't need the SFINAE tricks to detect if the
> comparison is valid, and so could check for irreflexivity in C++03
> mode.
>
> So I think ideally we would be able to check for irreflexivity for
> most algos in C++03, and for some (such as lower_bound) we would only
> be able to check for C++11 and later.
>
Ok, it looks like you really want to provide this check in pre-C++11
mode so here it is.
Tested under Linux x86_64.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: irreflexive_check.patch
Type: text/x-patch
Size: 38774 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150821/5193693f/attachment.bin>
More information about the Libstdc++
mailing list