Вывести параметр шаблона внешнего класса в вызов функции вложенного класса? - PullRequest
0 голосов
/ 16 января 2019

Есть ли способ вывести внешний шаблон во вложенном классе?

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);
}

Или я вынужден объявить вложенный класс снаружи? Это единственный обходной путь?

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);
}
...