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 ?)
Like this:
Live example
But please also see Why can templates only be implemented in the header file?. You (generally) cannot implement a template in the source file.