C++11 introduced default template arguments for function templates. See also Default template arguments for function templates.
But reading the C++ standard I could not find that it is legal to define a function template which use default template arguments for the first template argument, but not the other template arguments.
This would be the opposite of how default arguments are handled where all subsequent parameters must have a default argument supplied; or be a function parameter pack.
The difference between default arguments and default template arguments seems strange at a first glance, but allows for constructs as:
template <typename TException = std::exception, typename TObjectBuilder>
auto SwallowExceptions(const TObjectBuilder& rObjectBuilder) -> decltype(rObjectBuilder())
{
try
{
return rObjectBuilder();
}
catch (const TException&)
{
return decltype(rObjectBuilder())();
}
}
Is this legal C++ code and where in the standard can this be found?