Subject: Re: std::less, tuple, pointer ordering
From: Giuseppe D'Angelo (giuseppe.dangelo_at_[hidden])
Date: 2020-06-30 05:36:59
On 6/30/20 4:29 AM, Tony V E wrote:
> My thoughts have always been that tuple, optional, etc should implement less to call less on their elements.
> The standard should do the extra effort to do it right. But I expect less effort for user code.
Thanks for the feedback. Does anyone know if this something ever raised
or discussed formally at some point?
I'm not sure why it would be bring less burden for user code, unless
some pattern is established that allows to implement operator< and
std::less in a very similar way (ideally by reusing the same code). Or
is it because user code should not care?
> For users, I'm fine with their custom wrappers calling < on pointers, because it is implementation defined, and fine. The code you posted is probably defined on all platforms that Qt supports.
I didn't want to get there right away... In principle I could also be
happy if an implementation provided a strong guarantee that operator< on
pointers gives a total order (e.g. some constant/macro in a standard
header so I could static_assert on it). But that is a complete
non-starter: both GCC and MSVC already optimize away code based on
unspecified pointer comparisons:
And yes, we had dangerous code in Qt that needed to be fixed because of
-- Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer KDAB (France) S.A.S., a KDAB Group company Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com KDAB - The Qt, C++ and OpenGL Experts
STD-DISCUSSION list run by herb.sutter at gmail.com
Older Archives on Google Groups