简体   繁体   中英

How to use assert to check whether a weak_ptr is nullptr

The use of assert for checking whether a shared_ptr is not nullPtr is explained in c++ how to assert that all std::shared_ptr in a vector are referring to something but I don't find a decent way to check the same for a weak_ptr. I try to avoid converting it to shared_ptr so pls let me know your other solutions.

If you want to check whether the referenced model has already been deleted or whether the weak reference is empty -> use std::weak_ptr::expired().

reference documentation: https://en.cppreference.com/w/cpp/memory/weak_ptr/expired

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM