如何使用断言来检查weak_ptr是否为 nullptr
How to use assert to check whether a weak_ptr is nullptr
使用 assert 检查 shared_ptr 是否不是 nullPtr 在 c++ 中解释如何断言向量中的所有 std::shared_ptr 都引用了某些东西,但我没有找到一种体面的方法来检查weak_ptr相同的内容。我尽量避免将其转换为shared_ptr所以请让我知道您的其他解决方案。
如果要检查引用的模型是否已被删除或弱引用是否为空 ->请使用 std::weak_ptr::expire((。
参考文档:https://en.cppreference.com/w/cpp/memory/weak_ptr/expired
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 检查输入是否不是整数或数字
- 是否可以初始化不可复制类型的成员变量(或基类)
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 此代码是否违反一个定义规则
- 是否需要删除包含对象的"pair"?
- 是否可以从int转换为enum类类型
- 无论条件是否为true,if总是在c++中执行
- 如何找到大小'x'数组是否完全填充,在C++?
- 检查值是否在集合p1和p2中,但不在p3中
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- 在调用函数时,ptr** 和 ptr*& 之间是否有区别,或者首选C++?
- 视觉 C++编译器在计算其参数之前是否允许将函数 ptr 存储在寄存器中?
- 如何检测ptr在引用超出范围后是否仍在引用有效引用
- 当可以在类对象超出范围之前删除此数据时,类允许访问其数据(通过 ptr/it)是否设计不好
- 在声明char const *ptr ="某些字符"时是否有必要使用"const"?