Boost logo

Boost :

From: Daryle Walker (dwalker07_at_[hidden])
Date: 2003-08-23 03:37:16


On Friday, August 22, 2003, at 6:01 PM, Jan Langer wrote:

> what is needed for the lexicographic class to be included into boost?
> if it is a formal review (probably a really short one) i want to
> request it. maybe it can also be reviewed together with other utility
> components.

Do you have anything else forthcoming? If not, then don't bother
holding up this class for other potential co-components.

> the current version is in the boost-sandbox and consists of the
> following three files:
> boost/utility/lexicographic.hpp
> libs/utility/doc/lexicographic.html
> libs/utility/test/lexicographic_test.cpp

There's also a Jamfile in the test directory.

> and again a small decription
> ----------------------------
>
> It is a small class which helps to avoid error-prone if-else cascades
> if a certain lexicographic order for different sorting criteria has to
> be implemented.
>
> example:
>
> struct person
> {
> int age;
> std::string firstname, lastname;
> };
>
> bool operator < (person const &p1, person const &p2)
> {
> return boost::lexicographic
> (p1.lastname, p2.lastname, cmp_lower)
> (p1.firstname, p2.firstname, cmp_lower)
> (p2.age, p1.age);
> }
>
> ...
>
> std::set <person> group;
>
> now the member of group are sorted after last name in ascending order
> independent of lower or upper case. if the last name is equal they are
> sorted after the first name in the same manner, and if the whole name
> is equal they are sorted according to their age, with old people in
> front of the set.

Seems like a nice class. There is a std::lexicographical_compare. It
works on comparing two iterator sequences. It can automatically deal
with different sequence lengths, but your class can be used with any
method of component access. Your class can also spread out the
comparison code.

Daryle


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