Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > boost::bind

Reply
Thread Tools

boost::bind

 
 
STL-BOOST
Guest
Posts: n/a
 
      03-27-2008
Hi all:
how do i use bind for this:

struct fun
{
void exe()(int i){}
}

vector<fun> vec;
for_each(vec.begin(), vec.end(), ?);
 
Reply With Quote
 
 
 
 
Martin York
Guest
Posts: n/a
 
      03-27-2008
On Mar 26, 10:17 pm, STL-BOOST <(E-Mail Removed)> wrote:
> Hi all:
> how do i use bind for this:
>
> struct fun
> {
> void exe()(int i){}
> }
>
> vector<fun> vec;
> for_each(vec.begin(), vec.end(), ?);



Do you really want fun::exe to return a pointer to a function?
I am assuming it is just a method that takes an int:


#include <vector>
#include <algorithm>
#include <functional>

struct XXfun
{
void exe(int i){}
};
struct YYfun
{
operator()(int x){}
};


int main()
{
std::vector<XXfun> vec;
std::for_each(vec.begin(), vec.end(),
std::bind2nd(std::mem_fun_ref(&XXfun::exe),1));

std::vector<YYfun> data;
YYfun yyFun;
std::for_each(vec.begin(), vec.end(), yyFun);
}
 
Reply With Quote
 
 
 
 
STL-BOOST
Guest
Posts: n/a
 
      03-27-2008
On 3月27日, 下午2时27分, Martin York <(E-Mail Removed)> wrote:
> On Mar 26, 10:17 pm, STL-BOOST <(E-Mail Removed)> wrote:
>
> > Hi all:
> > how do i use bind for this:

>
> > struct fun
> > {
> > void exe()(int i){}
> > }

>
> > vector<fun> vec;
> > for_each(vec.begin(), vec.end(), ?);

>
> Do you really want fun::exe to return a pointer to a function?
> I am assuming it is just a method that takes an int:
>
> #include <vector>
> #include <algorithm>
> #include <functional>
>
> struct XXfun
> {
> void exe(int i){}
> };
> struct YYfun
> {
> operator()(int x){}
> };
>
> int main()
> {
> std::vector<XXfun> vec;
> std::for_each(vec.begin(), vec.end(),
> std::bind2nd(std::mem_fun_ref(&XXfun::exe),1));
>
> std::vector<YYfun> data;
> YYfun yyFun;
> std::for_each(vec.begin(), vec.end(), yyFun);
>
>
>
> }- 隐藏被引用文字 -
>
> - 显示引用的文字 -


but i want to use boost::bind, and how can i do
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments