Re: [Boost-users] [bind] Need Help - Function Composition
Thank you, Watanabe. B/Rgds Max ----- Original Message ----- From: Steven Watanabe To: boost-users@lists.boost.org Subject: Re: [Boost-users] [bind] Need Help - Function Composition Date: 2008-12-21 10:50:22 AMDG loadcom wrote:
I'm not sure if what you mean is that in your use case: boost::function f = make_less_by_func(boost::bind(...)); the temporarily constructed bind obj will go out of its lifetime before we use it via a refence to it?
Yes. the temporary is destroyed as soon as the boost::function constructor runs. f is then left with a reference to an object that has been destroyed.
But if I cannot declare
const F& func_;
instead of
F func_;
then why bother using another ref lib?
You can use a reference in some cases. Using Boost.Ref forces the caller to be explicit about whether to use a reference so presumably the user knows that it is safe.
or, in other words, is there a way to save this 'unneeded' copy construction and allow us to use
make_less_by_func(boost::bind(...)) ?
There is no way to avoid the copy while maintaining this interface. However, it is quite likely that the compiler can optimize away the copy when you are only using Boost.Bind with built in types.
btw, I'm not using ref lib frequently, but should boost::unwrap_ref be boost::unwrap_reference?
No. boost::unwrap_reference is a metafunction. In Christ, Steven Watanabe ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )
participants (1)
-
Max