Boost logo

Boost Users :

From: Tom Matelich (tmatelich_at_[hidden])
Date: 2002-09-26 10:40:31


I think the best solution for you would be to put boost::function<short>'s
in your map. Look at the example in the bind documentation at
http://www.boost.org/libs/bind/bind.html#with_boost_function

Tom

> -----Original Message-----
> From: dick.bridges_at_[hidden] [mailto:dick.bridges_at_[hidden]]
> Sent: Thursday, September 26, 2002 7:57 AM
> To: Boost-Users_at_[hidden]
> Subject: RE: [Boost-Users] bind: I just keep trying...
>
>
>
> I'm trying to store member function pointers. For purposes of this
> discussion, the key is an int.
>
> <context>
> X is the virtual base class for polymorphic message classes.
> all messages have a session-d attribute
>
> Ys are instances of classes derived from a virtual message hanler base
> class.
> foo() is the message handler function.
>
> Z is the 'message pump' that dispatches messages to Ys based upon the
> session-id.
>
> Y instances insert make_pair(session-id, message_handler)
> pairs into the
> map.
> (I think _1 is 'this' during the insert.)
>
> Z calls the Y instance message-handler using the session-id
> key to the
> map.
> </context>
>
>
>
>
>
>
> Mark Storer
>
>
> <mstorer_at_cardiff To:
> "'Boost-Users_at_[hidden]'" <Boost-Users_at_[hidden]>
>
> .com> cc:
>
>
> Subject: RE:
> [Boost-Users] bind: I just keep trying...
>
> 09/25/2002 04:47
>
>
> PM
>
>
> Please respond
>
>
> to Boost-Users
>
>
>
>
>
>
>
>
>
>
>
>
> 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/
>
>
>
> 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/
>
>
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor
> ---------------------~-->
> Home Selling? Try Us!
> http://us.click.yahoo.com/QrPZMC/iTmEAA/MVfIAA/EbFolB/TM
> --------------------------------------------------------------
> -------~->
>
> 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/
>
>

-----------------------------------------------------------------------
DISCLAIMER: Information contained in this message and/or
attachment(s) may contain confidential information of Zetec, Inc.
If you have received this transmission in error, please notify
the sender by return email.
-----------------------------------------------------------------------


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