|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-05 11:18:47
From: "Duane Murphy" <duanemurphy_at_[hidden]>
> Thank you! That's the ticket. I also noticed that the function object can
> be unnamed which avoids any name collisions.
I think that unnamed classes cannot be used as template parameters. Some
compilers allow this, but strictly speaking it's not legal. For example g++
2.95.3 complains.
> The template can also be
> static. Is there any side affects to be concerned about that? What does
> it mean to have a static template function inside a struct?
Nothing special; a static template generates static functions. An operator
cannot be static, though.
> I have another related question.
>
> I have a situation where I want to use a bind object within a bind object
> but the bindings are unrelated. In the documentation it explains that the
> nested binds are treated specially, is there a way around this special
> treatment?
Currently Bind doesn't provide a way to suppress the evaluation, but see
http://groups.yahoo.com/group/boost/files/protect.hpp
for a temporary solution:
#include <boost/bind.hpp>
#include "protect.hpp"
struct F
{
template<class G> int operator()(G g)
{
return g();
}
} f;
int g(int x)
{
return x;
}
int main()
{
boost::bind<int>( f, protect( boost::bind(g, 5) ) )();
}
I'll add protect to bind.hpp sometimes in the future. The only thing that's
holding me back is that I don't like the name.
Another useful wrapper is
http://groups.yahoo.com/group/boost/files/make_adaptable.hpp
that makes an adaptable function object with a fixed signature. It can be
used to get around the rvalue problem.
-- Peter Dimov Multi Media Ltd.
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