Using STL to Bind Multiple Function Arguments

In the past, I used the bind1st and bind2nd functions to perform direct operations on STL containers. Now I have a container of MyBase class pointers, which are simplified using the following:

class X
{
public:
    std :: string getName () const;
};

I want to call the following static function using for_each and bind both the first and second parameters as such:

StaticFuncClass :: doSomething (ptr-> getName (), funcReturningString ());

How to use for_each and bind both parameters of this function?

I am looking for something like:

for_each (ctr.begin (), ctr.end (), 
         bind2Args (StaticFuncClass :: doSomething (), 
                   mem_fun (& X :: getName), 
                   funcReturningString ());

, Boost , -, , STL?

.

+5
3

, , , :

struct callDoSomething {
  void operator()(const X* x){
    StaticFuncClass::doSomething(x->getName(), funcReturningString());
  }
};

for_each(ctr.begin(), ctr.end(), callDoSomething());

, bind .

+13

" STL" ... boost:: bind.

+4

, ( Jalf), :

void myFunc( const X* x ) { 
    StaticFuncClass::doSomething(x->getName(), funcrReturningString() ); 
}

for_each( c.begin(), c.end(), myFunc );
+3

All Articles