Suppose I have
class A,B,C;
const A a_def;
const B b_def;
const C c_def;
void f(A a=a_def, B b=b_def, C c=c_def);
This does, if I want to use the default parameters, only allow me to omit either just c, or b and c, or all three of them – but not just a or b alone. However, as the argument types cannot be mixed up, it would be completely unabiguous to call f(A(), C()), (or in fact f(B(), C(), A()): the order of arguments is arbitrary and actually meaningless).
To enable these alternative ways of calling the function, I now tend to overload every permutation manually
void f(A a, C c, B b=b_def) { f(a,b,c); }
void f(B b, A a=a_def, C c=c_def) { f(a,b,c); }
void f(B b, C c, A a=a_def) { f(a,b,c); }
void f(C c, A a=a_def, B b=b_def) { f(a,b,c); }
void f(C c, B b, A a=a_def) { f(a,b,c); }
which is acceptable for just three parameters (3!=6 permutations) but gets tedious at four (4!=24 permutations) and out of bounds at five parameters (5!=120 permutations).
Is there any way to get this functionality automatically, without actually having to do all the overloads, for instance by means of variable argument lists or some kind of template metaprogramming?
Look into the Boost.Parameters Library. It uses some template heavy lifting to get it to work. http://www.boost.org/doc/libs/1_37_0/libs/parameter/doc/html/index.html
It works basically by making your ‘named’ parameters into types that can be created, and assigned.