Extract first template parameter from a template template parameter and using it inside the class?

I have the following problem: a class template A with several template parameters, I want to build a class B that takes A as template parameter and extract the first template parameter of A in order to use it in some method(think of extracting int from std::vector<int> and returning the default int{}).

#include <iostream>

template<typename... Ts>
struct A {};

template<template <typename InnerType> typename U> // <--- I'd like to use InnerType!
struct B {
  InnerType foo() { return InnerType{}; }
};

int main()
{
  B<A<int>> b;
  std::cout << b.foo() << "n"; 

  return 0;
}

I knew this naive way wouldn’t compile, but I can’t figure out how to achieve something like that. Any tip is appreciated.

Source: Windows Questions C++

LEAVE A COMMENT