请考虑以下函数:
// Declaration in the .h file
class MyClass
{
template <class T> void function(T&& x) const;
};
// Definition in the .cpp file
template <class T> void MyClass::function(T&& x) const;
如果类型 T
具有不抛出异常的构造函数,我希望将此函数设置为 noexcept
。
如何实现?(我的意思是语法是什么?)
std::is_nothrow_constructible
进行检查。 - Jarod42T foo;
这样的nothrow 默认构造函数,但由于函数采用通用引用,我想知道您是否指的是从函数参数中nothrow构造函数,例如T foo{std::forward<T>(x)};
。 - Casey