Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-02-27 07:42:54

In message <Pine.LNX.4.10.10002270616210.13517-100000_at_boneone.endoframe.
com>, Braden N. McDaniel <braden_at_[hidden]> writes
>In order to use std::less (and the like), operator< needs to be defined.

This is not the case: std::less is not necessarily defined in terms of
operator< as you can specialise std::less, alternatively you can provide
your own comparator class; you are not restricted to not extending the
use of the standard library in this respect.

>shared_ptr appears to pursue the typical smart pointer aspiration of
>remaining semantically and syntactically like dumb pointers (within the
>constraints of the language and the constraints imposed by the value
>added by the particular smart pointer, of course), and the existing
>implementations of operator== and operator!= certainly support this. So
>why not continue in this direction by adding operator< ?

operator== and operator!= are not silent on the issue: They support the
conventional concept of comparison by identity. The reason that
operator< and its kin are not supported is that there is no useful or
unambiguous concept of ordering of identity.

Trying to follow the model for built-ins does not get you very far:
These operators exist but are only defined for the case that the
pointers are meaningfully ordered by pointing to objects in the same
array -- definitely not meaningful for objects allocated using object
new, as those for shared_ptr must be.

Which leads to the point that operator< is not the right place to focus
attention on here: std::less, as used in std::map et al, is not
necessarily defined in terms of operator<:

"For templates greater, less, greater_equal, and less_equal, the
specializations for any pointer type yield a total order, even if the
built-in operators <, >, <=, >= do not." [20.3.3 para 8]

  Kevlin Henney Without art we are nothing
  kevlin_at_[hidden] but monkeys with car keys

Boost list run by bdawes at, gregod at, cpdaniel at, john at