
Le 15/06/2011 13:15, Peter Dimov a écrit :
Stephan T. Lavavej wrote:
Right, that's what I was trying to say - internally, they are coupled, yet make_shared goes out of its way to be a free function.
My initial implementation of boost::make_shared was a self-contained header that didn't require any changes to shared_ptr (it would have worked with std::tr1::shared_ptr as well as it worked with boost::shared_ptr). This can only be done with a free function.
Now, this copied around the deleter a few times more than necessary and created problems with over-aligned types, so you're right that an optimized implementation needs support from shared_ptr. :-) (However, it can be argued that this support - the ability to ask for a deleter of a specific type to be default-constructed in place by shared_ptr - should be offered to users as well, not just to make_shared.)
Thank you for all those answers. I was wondering if ADL had something to do in this decision (I could not see how, at least not in a positive way), but it looks like this was not a criterion. -- Loïc