Consider the following code which uses \"template template\" parameters to instantiate a class template using multiple types:
#include
using
With a using
template alias, a new feature in C++11, you can create a one-parameter template that is equivalent to another template that has two parameters, one of which is defaulted.
template using Foo1 = Foo;
This creates Foo1
, a one-parameter template, even though Foo
technically has two arguments, one of which is defaulted. You can use it as:
do_something(int(55));
Alternatively, if C++11 features such as using
are not available, then you scan specify the default in your declaration of do_something
. This means then, unfortunately, that do_something
can no longer deal with simple one-arg templates. Hence, I think the using
method above is better.
template class Action, class T>
void do_something(const T& value);
If you take this approach, putting the default in the args to do_something
, then this default takes precedence over the default specified at the declaration Foo
. This is based on my experiments, and I can't comment with confidence on what is, and is not, standard. But I do think the using
trick is fully standards-compliant regarding C++11.
(Ubuntu clang version 3.0-6ubuntu3)