This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Add irreflexive comparison debug check
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: François Dumont <frs dot dumont at gmail dot com>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 30 Jul 2015 11:30:38 +0100
- Subject: Re: Add irreflexive comparison debug check
- Authentication-results: sourceware.org; auth=none
- References: <55B932A7 dot 2090806 at gmail dot com>
On 29/07/15 22:08 +0200, François Dumont wrote:
Hi
Here is a patch to add irreflexive debug check.
Awesome!
You can add PR libstdc++/60519 to the changelog.
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?
Assuming those validity checks are needed ...
+ struct _Irreflexive_checker
+ {
+#if __cplusplus >= 201103L
+ template<typename _It>
+ using __it_ref_t = typename std::iterator_traits<_It>::reference;
I'd just call this __ref_t, because where you use it the "it" part is
already implied by the template argument: __ref_t<_It>
Or you could add:
template<typename _It>
static typename std::iterator_traits<_It>::reference
__deref();
and replace every std::declval<__it_ref_t<_It>>() with __deref<_It>()
which is much shorter.
+ template<typename _It,
+ typename = decltype(
+ std::declval<__it_ref_t<_It> >() < std::declval<__it_ref_t<_It> >())>
N.B. as this is only for C++11 and later there's no need for the
spaces before the closing >