Re: [Boost-users] [bind] binding a boost::reference_wrapper to a function template

The problem is that tr is ref( t ) and is interpreted by bind as a request to store a reference to t. boost::bind( &foo< Test& >, tr ) should work, if this helps.
Peter, thank you very much. Could you please clarify what you mean however, because my understanding was that on construction, boost::bind internally just stores a copy of the bound argument without regard to the signature of the function to be invoked. The conversion of the argument to the type appropriate to the function invocation occurs when the functor is actually called. Is my understanding incorrect? Thank you. -------------------------------------------------------- NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error.

Barchenkov, Alexei (IT) wrote:
The problem is that tr is ref( t ) and is interpreted by bind as a request to store a reference to t. boost::bind( &foo< Test& >, tr ) should work, if this helps.
Peter, thank you very much. Could you please clarify what you mean however, because my understanding was that on construction, boost::bind internally just stores a copy of the bound argument without regard to the signature of the function to be invoked. The conversion of the argument to the type appropriate to the function invocation occurs when the functor is actually called.
boost::bind considers a reference_wrapper a special case and unwraps it before calling the function. Given boost::bind( f, ref(x) )(); it will call f with a reference to x, not with the value ref(x). This causes problems in your example because reference_wrapper's constructor is explicit and the reference to t cannot be converted to reference_wrapper<Test>. We've been toying with the idea of making reference_wrapper's constructor implicit. I don't remember why we decided against it. Some subtle problems with dangling references maybe?
participants (2)
-
Barchenkov, Alexei (IT)
-
Peter Dimov