As shown here, std::unique_ptr has two constexpr constructors for null pointers:
constexpr unique_ptr();
constexpr unique_ptr( nullptr_t );
I have two questions for these two constructors:
(1) Why do we need two? Can't we just declare one as:
constexpr unique_ptr( nullptr_t = nullptr );
(2) Is the constexpr really useful? I tried doing this in my code but it didn't compile (g++ 6.1.0, -std=c++14):
constexpr std::unique_ptr<int> p;
// error: the type 'const std::unique_ptr<int>' of constexpr variable 'p'
// is not literal because 'std::unique_ptr<int>' has a non-trivial destructor
Aucun commentaire:
Enregistrer un commentaire