Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-07-11 08:50:27


Philippe Vaucher wrote:
>> How do you make a std::set of structs, pairs, or tuples?
>
> Maybe it was already said (didn't read the whole thread), but I
> thought I'd add my 0.02$.
>
> I think we should not define meaningless operator< for the
> structs/whatever, and let the user define one if he wants to use
> those structs in a set.

That's the claim being made in this thread, true.

The user can't necessarily define operator< for a foreign class because
different users may have different ideas about what operator< should do, so
their translation units won't be able to coexist. It is the responsibility
of the author of the class to define its operator< (if there is one.)

This leaves us with the option of defining and using custom comparators. So,
if the author of pair<> does nothing, every time you need to make a set out
of pair<X, Y>, you'll need to define a separate function object for it. This
isn't very convenient; most of these function objects would end up being
exact copies.

So maybe the author of pair<> needs to provide a comparator.

template<class P> struct pair_compare
{
    bool operator()( P const & p ) const
    {
        // ???
    }
};

What would you put in the ??? portion? (Warning, this is a trap.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk