微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么 libc++ 没有实现 shared_ptr 的模板化移动赋值运算符 noexcept

如何解决为什么 libc++ 没有实现 shared_ptr 的模板化移动赋值运算符 noexcept

根据cppreference,shared_ptr 的模板化移动赋值运算符应该是noexceptLibstdc++ 实现了它,但 libc++ 没有实现。实际上,swap 成员函数和移动构造函数都是 noexcept。为什么?

template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
    __compatible_with<_Yp,typename shared_ptr<_Tp>::element_type>::value,shared_ptr<_Tp>&
>::type
shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) // <--- not noexcept
{
    shared_ptr(_VSTD::move(__r)).swap(*this);
    return *this;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。