|
Boost : |
From: Daryle Walker (darylew_at_[hidden])
Date: 2006-07-18 18:24:06
On 7/10/06 4:52 PM, "Peter Dimov" <pdimov_at_[hidden]> wrote:
> Daryle Walker wrote:
>
>> Looking at <http://www.boost.org/libs/smart_ptr/shared_ptr.htm>, i.e.
>> the Boost version, it seems that the authors fell into the "fake
>> operator <" trap. If any of those authors are reading this, can you
>> tell us why you added the fake operator instead of a custom-named
>> comparison class?
>
> shared_ptr defines operator< for map<shared_ptr<>, V> to work. What do you
> mean by "fake"?
I mean just what you did, defining such an operator _only_ to allow
associative containers to use a default template argument, even if the
operator doesn't fit the class's model otherwise. If we take your view to
the extreme, then why should that template argument for comparison exist at
all? We could always define an operator "<" and let associative containers
use that. (Of course, such an action would forbid containers with the same
key type but different comparison criteria.)
What's wrong with defining a separate comparison class? Having to specify
the class's name does not change the computation complexity, only your
amount of typing (and you can use a typedef for multiple uses of the name).
Typing a model involves not only what aspects to include, but what to
exclude. Don't corrupt the model for convenience.
Finally, using the comparison argument localizes the criteria. The whole
operator "<" alternative makes the decision global, even for those that
don't want/need it. I view the fake operator "<" as a code smell, and
probably should be added to any official lists.
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk