
On 08/31/2006 04:05 PM, Paul Mensonides wrote: [snip]
Actually, you only need combinatorial forwarding on the function that takes arguments from the client. You don't need it elsewhere because then you don't have temporaries.
[snip]
One problem of forwarding is arity (which can be more-or-less solved with code generation). The more stubborn problem with forwarding is temporaries. They cannot be bound to a non-const reference, and the template mechanism cannot deduce T as const U in a parameter of type T&. OTOH, non-temporaries don't have any problem deducing T as U or const U in a parameter of type T&. Unfortunately, the only way to handle it transparently is to overload via cv-qualifier--which leads the the combinatorial explosion when multiple parameters are involved.
Given the above, you could solve (i.e. avoid) the combinatorial problem by linearizing the input.
Paul, could explain what's meant by "linearizing the input"? I'm unfamiliar with that phrase :(
If you have no temporaries, you can just use T& and T will bind correctly to a cv-qualified type.
To get rid of temporaries (which can't bind to T&) you need:
template<class T> inline T& identity(T& x) { return x; } template<class T> inline const T& identity(const T& x) { return x; } template<class T> inline volatile T& identity(volatile T& x) { return x; } template<class T> inline const volatile T& identity(const volatile T& x) { return x; }
What was called before as
f(a, b, c);
can be called as
f(identity(a), identity(b), identity(c));
...which is relatively easily generated via the preprocessor--especially with variadic macros:
F(a, b, c) -> f(identity(a), identity(b), identity(c))
I'm afraid I don't understand. Could you provide some code, maybe for just 2 to 3 parameters, which is like the ctor_template_test.cpp code in the vault. IOW, show: template<class U0, class U1> sub( linear_arg<U0>::type u0, linear_arg<U1>::type u1) : Super(u0, u1) {} where: template<class T> structlinear_arg; is a metafunction. Or could you provide some other code or sketch of code to make it a little clearer? Thanks for your interest. -regards, Larry Evans