Le 25/12/2015 18:38, Bjorn Reese a écrit :
On 12/18/2015 05:54 PM, Vicente J. Botet Escriba wrote:
There is a draft proposal not yet finished at
https://github.com/viboes/std-make/blob/master/doc/proposal/factories/DXXXX_...
I realize that you are attempting to generalize pre-existing make factories, but I still wanted to raise the following problem because Yes, the make function is just a generalization. that is the main reason why I often have to avoid using make_shared.
If I have a class T that always must be created as a shared_ptr (e.g. because it relies on enable_shared_from_this<T>), then I can ensure that the class can only be constructed via the factory by making the constructor of T private, and let the factory be a friend of T. This works fine if my factory is a static T::create(args...) function, but not when using make_shared<T>(args...) because in practice it uses internal helper functions that I cannot make friends of my class.
I believe there is a place for this kind of classes and to have an associated factory. The question is how to recognize these kind of classes. My library would only help you to overload make_custom so that you can write shared_ptr<T> ptr = make<T>(args...); make_custom will replace your T::create(args...). Even if the library wouldn't help you a lot (as you need to customize), would you prefer make<T>(args...) to T::create(args...)? Maybe inheriting T from a specific class could help to identify this kind of classes and so the customization. Vicente