vendredi 11 juin 2021

shared_ptr and unique_ptr constructor

When I use smart pointers, I always need to construct it with the factory functions, e.g. std::make_shared<T> and std::make_unique<T>, I don't use the constructor which takes a pointer because I try to avoid any usage/appearances of new. But my question is why C++ standard didn't include a constructor that takes argument list to forward to the type T? Like instead of shared_ptr<T> make_shared(Args&&...), can we have following:

shared_ptr<T>::shared_ptr(Args&&...) {...}
unique_ptr<T>::unique_ptr(Args&&...) {...}

Aucun commentaire:

Enregistrer un commentaire