1

Is there a way to deduce the outer template in a nested class?

template<class T>
struct A{
    struct B{};
};

template<class T> void f(typename A<T>::B b){} // hard to deduce T?

int main(){
  A<double>::B b;
  f(b); // no matching function for call to 'f(A<double>::B&)', meant to call f<double>(b);
}

Or I am forced to declare the nested class outside? Is this the only workaround?

template<class T> struct B_impl{};

template<class T>
struct A{
    using B = B_impl<T>;
};

template<class T> void f(B_impl<T> b){} // to bad there is no mention of A here

int main(){
  A<double>::B b;
  f(b);
}
alfC
  • 14,261
  • 4
  • 67
  • 118

0 Answers0