Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 2000-06-08 13:24:17

I like using std::pair for solving this problem. Just use std::pair
like a lisp-style linked-list, and the operator< for std::pair gives
you lexicographical compare for free.

If you need members of type A, B, C, and D then create the list:

pair<A, pair<B, pair<C,D> >

or if you want to use a nil class:

pair<A, pair<B, pair<C, pair<D, nil> > >



Dave Abrahams writes:
> --- In boost_at_[hidden], "Dave Abrahams" <abrahams_at_m...> wrote:
> > How often have you written an aggregate class from which you needed
> > to use all or some data members to form a sort key for a standard
> > container or algorithm? Happens to me all the time. As such, I
> > propose the following suite of template functions as an addition to
> > utility.hpp (please, someone, suggest a better name!)
> That'll teach me to post before testing; my code doesn't work. I
> still think it would be good to find a way to address this problem,
> but I am less convinced I have the right way, even after I fix the
> bugs. Ultimately, one doesn't want a family of template functions,
> but of classes (so that they can be used in the standard associative
> containers). Also, it would be good to be able to specify the
> comparison criterion for each sub-comonent.
> -Dave
> ------------------------------------------------------------------------
> Would you like to save big on your phone bill -- and keep on saving
> more each month? Join beMANY! Our huge buying group gives you Long Distance
> rates which fall monthly, plus an extra $60 in FREE calls!
> ------------------------------------------------------------------------

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