Boost logo

Boost :

From: Jim Argeropoulos (jaa_at_[hidden])
Date: 2000-01-15 12:14:33


OK, Jeremy

I'll buy the fact that works, even though my compiler won't. But I have two
problems with that as a solution:

First and most important to me, it doesn't solve the problem of comparing by
more than one attribute. You can't chain multiple calls to compose_f_gx_hy()
with logical_and or logical_or because they require the same type.

Second, few practicing programmers are going to figure it out. If we call it
a solution I would like to see some helper functions for it. Of the 30
programmers I work with I would only expect one other to ever figure out how
to put compose_f_gx_hy() to use on their own. Its just too abstract for
them. Maybe in a few years, but not today. Those who partake in this mailing
list think at a different level than the average programmer.

Jim
----- Original Message -----
From: <jsiek_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Saturday, January 15, 2000 2:32 AM
Subject: [boost] MemberFunctionCompare part 2

> Hi Jim,
>
> I'm afraid there is already a good solution to the problem you
> describe, and it is by one of our members here at boost, Nicolai
> Jusuttis. With his compose library, and with the member function
> functor from the standard, you can do the same things that your
> library does. Here's the example you gave rewritten using the compose
> library.
>
> Ciao,
>
> Jeremy
>
>
> #include <vector>
> #include <string>
> #include <algorithm>
> #include <iostream>
> #include <boost/compose.hpp>
>
> using namespace std;
> using namespace boost;
>
> class Person
> {
> public:
> Person(const string& n) : _name(n) { }
> const string& GetName ( ) const { return _name; }
> protected:
> string _name;
> };
>
> typedef vector < Person* > PersonVector ;
> typedef PersonVector::iterator PersonVecIter ;
> typedef PersonVector::const_iterator PersonVecConstIter ;
>
> int
> main(int,char*[])
> {
> const char* names[] = { "fred", "walter", "joe", "suzy", "jim" };
> PersonVector aPersonVec;
> for (int i = 0; i < sizeof(names)/sizeof(const char*); ++i)
> aPersonVec.push_back(new Person(names[i]));
>
> // sort the people by name
> sort(aPersonVec.begin(), aPersonVec.end(),
> compose_f_gx_hy(less<string>(),
> mem_fun(Person::GetName),
> mem_fun(Person::GetName)));
>
> // print out the names of the people
> transform(aPersonVec.begin(), aPersonVec.end(),
> ostream_iterator<string>(cout, " "),
> mem_fun(Person::GetName));
> cout << endl;
>
> for (int i = 0; i < aPersonVec.size(); ++i)
> delete aPersonVec[i];
>
> return 0;
> }
>
>
> ------------------------------------------------------------------------
> Want to send money instantly to anyone, anywhere, anytime?
> You can today at X.com - and we'll give you $20 to try it! Sign
> up today at X.com. It's quick, free, & there's no obligation!
> http://click.egroups.com/1/332/1/_/9351/_/947925149/
>
> -- 20 megs of disk space in your group's Document Vault
> -- http://www.egroups.com/docvault/boost/?m=1
>
>


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