While trying to apply policy-based design, I got stuck on this one (simplified):
template <class TPrintPolicy, typename T>
struct A : private TPrintPolicy {
using TPrintPolicy::Print;
T t;
void Foo() {
Print(t);
}
};
struct IntPolicy {
void Print(int n) {
std::cout << n << std::endl;
}
};
int main(int argc, char* argv[]) {
A<IntPolicy, int> a;
a.Foo();
return 0;
}
And here's the question: How should I redefine class A so that it would be possible to provide only the policy parameter to the A template, to let it infer T on its own, like this:
A<IntPolicy> a;
Preferrably, policy definition should not be much more complicated then it is now. Any ideas?
EDIT:
I forgot to mention that I do not want a policy to export a typedef. That is of course the easy solution, but cannot A infer the type of T on its own?