C++ Logo

sg12

Advanced search

Re: [ub] Justification for < not being a total order on pointers?

From: Nevin Liber <nevin_at_[hidden]>
Date: Wed, 16 Oct 2013 16:25:19 -0500
On 16 October 2013 16:15, Christopher Jefferson <chris_at_[hidden]>wrote:

> On 16 October 2013 00:14, Gabriel Dos Reis <gdr_at_[hidden]> wrote:
> > Nevin --
> > Are you asking that operator< be a total order on
> std::deque<T>::iterator?
> >
>
> On a practical note, I believe this would arise naturally, if
> operator< was a total order on pointers.


No, it does not. It would be a pessimization. As pointed out on the LWG
reflector:

On 16 October 2013 13:25, Stephan T. Lavavej <stl_at_[hidden]>wrote:

> There is an efficiency concern here. Our deque iterators are represented
> with a parent pointer and an index, and op< compares only the index (same
> for op==). If we had to provide a total order, we'd need to insert extra
> instructions.



> Also at the moment there
> isn't an alternative, because there isn't a
> std::less<std::deque<T>::iterator>.
>

(A) Sure there is; it just calls down to operator<.
(B) It doesn't provide any more of a guarantee of total ordering than
operator< does.
-- 
 Nevin ":-)" Liber  <mailto:nevin_at_[hidden]>  (847) 691-1404

Received on 2013-10-16 23:26:01