|
Boost Users : |
From: Jean-Marc Prud'homme (JPrudhomme_at_[hidden])
Date: 2003-06-10 11:01:37
Hi Paul,
_1 is a placeholder argument. When you write
bind(&CDocumentAttachments::Execute, _1, _T("print"))
you are creating a functor that can be called with a single argument
of type CDocumentAttachments. This is what is required by the for_each
algorithm. It is equivalent to
bind<HINSTANCE>(mem_fn(&CDocumentAttachments::Execute), _1, _T("print"))
Look at the mem_fn doc.
You still need this kind of functor if you add more arguments to
CDocumentAttachments::Execute. This should create the functor you
need
bind(&CDocumentAttachments::Execute, _1, _T("print"), false)
Hope this helps,
Jean-Marc
-----Original Message-----
From: Paul Thompson [mailto:friedegg_at_[hidden]]
Sent: Tuesday, June 10, 2003 7:54 AM
To: Boost-Users_at_[hidden]
Subject: [Boost-Users] Struggling with bind
Hi all.
I've been using boost::bind to work around deficiencies with
std::mem_fun_ref and std::bind2nd under MSVC6.
I have a class called CDocumentAttachments which had a member
function thus:
HINSTANCE Execute(LPCTSTR verb) const;
I was using bind with this as follows:
for_each(filenames.begin(),
filenames.end(),
bind(&CDocumentAttachments::Execute, _1, _T("print")));
"filenames" is a const vector of CDocumentAttachments objects.
This worked fine.
A little later on in development, I changed the function signature for
CDocumentAttachments::Execute to:
HINSTANCE Execute(LPCTSTR verb, bool visible) const;
How will I pass the extra bool to bind? I can't find any examples of
passing more than one parameter to a member function.
I thought about (among many others)
for_each(filenames.begin(),
filenames.end(),
bind(&CDocumentAttachments::Execute, _2, _T("print"),
false));
but the compiler (VC6) complains with two of the following:
k:\vc\include\boost\bind.hpp(760) : error C2679: binary '[' : no
operator
defined which takes a right-hand operand of type 'const class
boost::arg<2>'
(or there is no acceptable conversion)
k:\vc\include\boost\bind\bind_template.hpp(33) : see
reference to
function template instantiation 'struct HINSTANCE__ *__cdecl
boost::_bi::evaluator3<struct HINSTANCE__ *>::eval(const class
boost::_bi::list3<class boost::arg<2>,class boost::
_bi::value<char *>,class boost::_bi::value<bool> > &,struct
boost::_mfi::cmf2<struct HINSTANCE__ *,class
CDocumentAttachments,char const
*,bool>,class boost::_bi::list1<class CDocumentAttachments const &>
&)'
being compiled
I know I'm being really thick here, and I'm sure there's something
really
obvious that I'm missing, but reading through the documentation hasn't
helped me.
Thank you very much.
Paul
-- Paul Thompson Programmer McLellan Software Design Ltd. 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