dimanche 28 février 2021

std::unique_ptr::reset overloads questions

From the https://en.cppreference.com/w/cpp/memory/unique_ptr/reset members of the primary template, unique_ptr

void reset( pointer ptr = pointer() ) noexcept;     (1)     

        
template< class U >
void reset( U ) noexcept;       (2)     
void reset( std::nullptr_t p = nullptr ) noexcept;      (3)     

For me it seems that for (1) if no parameter is giver then default constructor of the pointer's type will be called. But it should behave as a nullptr, so that the pointer inside unique_ptr will be deleted and it will be set to null, how come?

Explanation for the (2) is

2) Behaves the same as the reset member of the primary template, except that it will only participate in overload resolution if either:    
    U is the same type as pointer, or
    pointer is the same type as element_type* and U is a pointer type V* such that V(*)[] is convertible to element_type(*)[].

I can't really understand it, can somebody please explain/rephrase?

Aucun commentaire:

Enregistrer un commentaire