Ger*_*ago 3 c++ any assignment-operator noexcept c++17
问题很简单.
这是模板化operator = for的声明std::any
:
template<typename ValueType>
any& operator=( ValueType&& rhs );
Run Code Online (Sandbox Code Playgroud)
我希望它是:
template<typename ValueType>
any& operator=( ValueType&& rhs ) noexcept(noexcept(std::declval<std::any>() = std::forward<ValueType>(std::declval<ValueType>()));
Run Code Online (Sandbox Code Playgroud)
也就是说,如果您可以以noexcept方式将ValueType复制分配给任何一个,那么您应该能够使用noexcept.
也许我错过了什么.
字面上的答案是这样的规范是递归的(你说的是赋值应该是noexcept
赋值的noexcept
).
但可能更多有用的答案是,因为any
可能要分配,你只能真的有noexcept
在该情况下,分配decay_t<ValueType>
是
ValueType
指定noexcept
条件的唯一方法是要求您还指定"足够小"的含义 - 这将限制实现自由度,以获得可疑的收益.
标准库通常不使用条件noexcept - 那么为什么这是......异常?