Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   boost::bind (http://www.velocityreviews.com/forums/t602144-boost-bind.html)

STL-BOOST 03-27-2008 05:17 AM

boost::bind
 
Hi all:
how do i use bind for this:

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

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

Martin York 03-27-2008 06:27 AM

Re: boost::bind
 
On Mar 26, 10:17 pm, STL-BOOST <wartal...@gmail.com> 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);
}

STL-BOOST 03-27-2008 07:05 AM

Re: boost::bind
 
On 3月27日, 下午2时27分, Martin York <Martin.YorkAma....@gmail.com> wrote:
> On Mar 26, 10:17 pm, STL-BOOST <wartal...@gmail.com> 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


All times are GMT. The time now is 09:55 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.