Consider the following code:
template < typename T >
struct A
{
struct B { };
};
template < typename T >
void f( typename A::B ) {
How can I avoid explicitly specifying int while calling f?
Just make B
declare its nesting class type
template < typename T >
struct A
{
struct B { typedef A outer; };
};
Then you can deduce it. The following takes the outer template, the inner's typedef and a return type
template class Outer, typename D, typename R = void >
struct nesting { };
template class Outer, typename Arg, typename R>
struct nesting< Outer, Outer, R > {
typedef Arg arg1_type;
typedef R type;
};
template < typename T >
typename nesting::type
f(T) {
/* nesting::arg1_type is A's T */
}