The (draft) standard says:
// 20.8.1.2.1, constructors
...
template <class U, class E>
unique_ptr(unique_ptr<U, E>&& u) noexcept;
template <class U>
unique_ptr(auto_ptr<U>&& u) noexcept;
Those are constructors from any unique_ptr. The standard further restricts their usage by clauses like this:
24 Remarks: This constructor shall not participate in overload resolution unless U*
is implicitly convertible to T*
and D
is the same type as default_delete<T>
The effect of this remark is that unique_ptr<T>
is constructible from unique_ptr<U>
precisely U*
is convertible to T*
(and all deleter requirements are met). In particular, when T
is an unambiguous public base class of U
.
Since the constructor is not explicit
, it serves as an implicit converter from unique_ptr<U>
to unique_ptr<T>
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…