[util.smartptr.shared.cast] (original) (raw)

20 Memory management library [mem]

20.3 Smart pointers [smartptr]

20.3.2 Shared-ownership pointers [util.sharedptr]

20.3.2.2 Class template shared_ptr [util.smartptr.shared]

20.3.2.2.10 Casts [util.smartptr.shared.cast]

Mandates: The expression static_cast<T*>((U*)nullptr) is well-formed.

Returns: shared_ptr<T>(R, static_cast<typename shared_ptr<T>::element_type*>(r.get())) where R is r for the first overload, andstd​::​move(r) for the second.

[Note 1:

The seemingly equivalent expressionshared_ptr<T>(static_cast<T*>(r.get()))can result in undefined behavior, attempting to delete the same object twice.

— _end note_]

Mandates: The expression dynamic_cast<T*>((U*)nullptr) is well-formed.

The expression dynamic_cast<typename shared_ptr<T>​::​element_type*>(r.get()) is well-formed.

Preconditions: The expression dynamic_cast<typename shared_ptr<T>​::​element_type*>(r.get()) has well-defined behavior.

Returns:

[Note 2:

The seemingly equivalent expressionshared_ptr<T>(dynamic_cast<T*>(r.get())) can result in undefined behavior, attempting to delete the same object twice.

— _end note_]

Mandates: The expression const_cast<T*>((U*)nullptr) is well-formed.

Returns: shared_ptr<T>(R, const_cast<typename shared_ptr<T>::element_type*>(r.get())) where R is r for the first overload, andstd​::​move(r) for the second.

[Note 3:

The seemingly equivalent expressionshared_ptr<T>(const_cast<T*>(r.get())) can result in undefined behavior, attempting to delete the same object twice.

— _end note_]

Mandates: The expression reinterpret_cast<T*>((U*)nullptr) is well-formed.

Returns: shared_ptr<T>(R, reinterpret_cast<typename shared_ptr<T>::element_type*>(r.get())) where R is r for the first overload, andstd​::​move(r) for the second.

[Note 4:

The seemingly equivalent expressionshared_ptr<T>(reinterpret_cast<T*>(r.get())) can result in undefined behavior, attempting to delete the same object twice.

— _end note_]