boost make_shared takes in a const reference. Any way to get around this?

http://www.boost.org/doc/libs/1_39_0/libs/smart_ptr/make_shared.html says: "If you need to pass a non-const reference to a constructor of T, you may do so by wrapping the parameter in a call to boost::ref." Other text on that page seems to support Rüdiger Hanke's answer.


Can't speak for the authors of he function, but ... you've got to make a choice. If the function would use a non-const reference, then you couldn't pass const objects to constructors that take const references.

In my experience, constructors taking const references are far more common than constructors taking mutable references.

Constructors can have n parameters, so you can't just provide a single overload, but have to take into account any combination of const/non-const which results in an exponential explosion of overloads you'd need if you'd want to provide overloads for all of them. C++0x and perfect forwarding should provide a solution for this issue I think.

Tags:

C++

Boost