Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的函数模板:
template <typename T> void f(vector<T> &a) noexcept(noexcept( /* ??? */ ))
=鉴于赋值运算符T具有noexcept规范,我想指定此函数不会引发异常。有没有办法做到这一点?
=
T
noexcept
你可以这样做:
template<typename T> void f(std::vector<T>& a) noexcept(std::is_nothrow_copy_assignable<T>::value) {...}
它对noexceptif 复制分配T值本身声明了一个条件noexcept。您可以进一步考虑到 move-assigning T。