I want my builder method Class::create() to return the unique_ptr
Why?
1) This design is not enforcing the shared ownership (and atomic lock). unique_ptr is very efficient and has same size as void*
2) Still, it is easy to move to shared_ptr on the class user's side (but only when client would like to share the instance for multiple ownership)
So. I want to pay only for what I'm using
But. I need some class instance's methods to return "this" pointer.
If I inherit class from enable_shared_from_this I just use return shared_from_this but I think it won't be related to the unique ownership
In other words, will the unique_ptr created somewhere in class (without using shared_from_this() of course) somehow be related to (potential) shared_ptr created from this unique_ptr? Or it will lead to double deletion problem?
thiscan easily be put into aunique_ptrand there is no problem to solve like there is withshared_ptr. - Galikshared_ptr widget1 = move(Widget::create()). Then auto child = widget1->createChild() where each child should receive parent's shared_ptr -> to be converted in weak_ptr inside the Child. This means that in createChild I have to access to shared_from_this() - barney