|
Boost Users : |
From: Mark Storer (mstorer_at_[hidden])
Date: 2002-09-25 18:47:49
I'm a little confused as to what you're aiming for here... a map of ints to
function pointers (that can point to Y::foo)?
This should do the trick, provided I'm recalling my function pointer
declarations correctly
std::map<int, short()(*X)>
Further boost::bind creates an INSTANCE of a functor. Giving the compiler
an instance when it wants a type is not a good way to keep it happy.
Now if what you're actually after is calling Y::foo on a colleciton of Y's,
then you don't need a collection of function pointers for each instance in
the first place, which is where bind comes in. According to my flimsy
understanding of bind (I haven't used it yet), this should do the trick:
X someX;
std::vector<Y> &wise = BuildYs(); // wise == plural of Y
std::for_each(
wise.begin(),
wise.end(),
boost::bind<short>(&Y::foo, &someX)
);
If you want the X parameter to vary from one call of foo to the next, I
suggest rolling your own loop... or incorporating the X* into Y, at which
point you can get rid of the X* parameter, and use boost::bind(&Y::foo), or
std::mem_fun(&Y::foo).
--Mark Storer
Software Engineer
Cardiff Software
#include <disclaimer>
typedef std::disclaimer<Cardiff> Discard;
-----Original Message-----
From: dick.bridges_at_[hidden] [mailto:dick.bridges_at_[hidden]]
Sent: Wednesday, September 25, 2002 4:08 PM
To: boost-users_at_[hidden]
Subject: [Boost-Users] bind: I just keep trying...
Everytime I think I have a clue, I'm reminded how little I REALLY
understand.
<error compiler='VC6SP4'>
'map' : invalid template argument for '_Ty', type expected
</error>
<snippet>
struct X
{
}
struct Y
{
short foo(X*);
}
struct Z
{
map<int, bind(&Y::foo, _1, _2) > myMap;
}
</snippet>
I thought I saw how to do this somewhere on the website but I sure can't
find it now. Any help GREATFULLY appreciated.
Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net