Thank you for your replies.

bind1st(mem_fun(&Foo::bar), this))

was what I considered first, but it seems that it won't work if 'bar'

takes reference to argument type (like in my example above). At least

not on MS VS 2005.

well, here is my implementation for those who want to see the diff

(NOTE: I renamed my function "pass_to_mem_fun" because I thought it was

clearer than "call_mem_fun")

template <typename _Result, typename T, typename ArgT>

class pass_to_mem_fun_t : public std::unary_function<ArgT, _Result>

{

public:

explicit pass_to_mem_fun_t(_Result (T::*_Pm)(ArgT), T *pThis)

: _Pmemfun(_Pm), _this(pThis)

{

}

_Result operator()(ArgT _Pleft) const

{ // call function

return (_this->*_Pmemfun)(_Pleft);

}

private:

T *_this;

_Result (T::*_Pmemfun)(ArgT); // the member function pointer

};

template <typename _Result, typename T, typename ArgT>

class pass_to_const_mem_fun_t : public std::unary_function<ArgT,

_Result>

{

public:

explicit pass_to_const_mem_fun_t(_Result (T::*_Pm)(ArgT) const, T

const *pThis)

: _Pmemfun(_Pm), _this(pThis)

{

}

_Result operator()(ArgT _Pleft) const

{ // call function

return (_this->*_Pmemfun)(_Pleft);

}

private:

T const *_this;

_Result (T::*_Pmemfun)(ArgT) const; // the member function pointer

};

template <typename _Result, typename T, typename ArgT>

pass_to_mem_fun_t<_Result, T, ArgT>

pass_to_mem_fun(_Result (T::*pFn)(ArgT), T *pThis)

{

return pass_to_mem_fun_t<_Result, T, ArgT>(pFn, pThis);

}

template <typename _Result, typename T, typename ArgT>

pass_to_const_mem_fun_t<_Result, const T, ArgT>

pass_to_mem_fun(_Result (T::*pFn)(ArgT) const, T const*pThis)

{

return pass_to_const_mem_fun_t<_Result, const T, ArgT>(pFn, pThis);

}

------------

in the foo-bar example I gave, the call would look like this:

for_each(bars.begin(), bars.end(), pass_to_mem_fun(&Foo::printABar,

this));

====

Anyhow, if you see that the "Foo bar" example I posted can be compiled

with any of the standard alternatives, I am eager to know it.

Thank you,

Aleksandar

On Nov 15, 4:13 pm, Pete Becker <p...@versatilecoding.comwrote:

rile wrote:

void doSomethingWithEach()

{

for_each<myv.begin(), myv.end(), call_mem_fun(&Foo::doSomething,

this));

} bind1st(mem_fun(&Foo::doSomething), this)

If you have TR1 you can make it a bit simpler:

bind(&Foo::doSomething, this, _1)

--

-- Pete

Roundhouse Consulting, Ltd. (www.versatilecoding.com)

Author of "The Standard C++ Library Extensions: a Tutorial and

Reference." (www.petebecker.com/tr1book)