[bind][make_shared] compilation failure with ref arg

The last statement below fails to compile with boost 1.39.0 on MSVC 8. Am I doing anything obviously wrong? Any help is appreciated. Jeff #include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> struct X { X(const int* ) {} }; struct Y { Y(int& ) {} }; int _main(int argc, char* argv[]) { int i = 123; boost::bind(&boost::make_shared<int>); boost::bind(&boost::make_shared<int, int>, i); boost::bind(&boost::make_shared<int, int>, 123); boost::bind(&boost::make_shared<X, int*>, &i); boost::bind(&boost::make_shared<Y, int&>, boost::ref(i)); return 0; }

Jeff Flinn wrote:
The last statement below fails to compile with boost 1.39.0 on MSVC 8. Am I doing anything obviously wrong? Any help is appreciated.
...
boost::bind(&boost::make_shared<Y, int&>, boost::ref(i));
Under C++03 compilers, make_shared takes its arguments by const reference: template<class T, class A1> shared_ptr<T> make_shared( A1 const & a1 ); MSVC doesn't like the A1=int& case because it forms the questionably valid "int& const&". boost::bind( &boost::make_shared<Y, boost::reference_wrapper<int> >, boost::ref(i) ); works though. This is what make_shared<Y>( ref(i) ) would instantiate.

Peter Dimov wrote:
Jeff Flinn wrote:
The last statement below fails to compile with boost 1.39.0 on MSVC 8. Am I doing anything obviously wrong? Any help is appreciated.
...
boost::bind(&boost::make_shared<Y, int&>, boost::ref(i));
Under C++03 compilers, make_shared takes its arguments by const reference:
template<class T, class A1> shared_ptr<T> make_shared( A1 const & a1 );
MSVC doesn't like the A1=int& case because it forms the questionably valid "int& const&".
boost::bind( &boost::make_shared<Y, boost::reference_wrapper<int> >, boost::ref(i) );
works though. This is what make_shared<Y>( ref(i) ) would instantiate.
Ah, thanks Peter! Jeff
participants (2)
-
Jeff Flinn
-
Peter Dimov