Use of the noexcept specifier in function declaration and definition?
问题 Consider the following function: // 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; I want to make this function noexcept if the type T is nothrow constructible. How to do that ? (I mean what is the syntax ?) 回答1: Like this: #include <type_traits> // Declaration in the .h file class MyClass { public: template <class T> void function(T&& x) noexcept(std::is