6

I have class Foo, which has two template parameters, A and B:

template<typename A, typename B>
struct Foo {};

Also I have class Base, which has one template template parameter:

template<template<typename B> typename Foo>
struct Base {};

I want to write class Derived assuming the following:

  • Derived has one template parameter (A)
  • Derived extends class Base
  • Derived passes as template parameter to class Base class Foo, but with one parameter "currying" (A)

How can I do this?


Here is my (not working) solution:

template<template<typename B> typename Foo>
struct Base {};

template<typename A, typename B>
struct Foo {};

template<template<typename A, typename B> typename Foo, typename A>
struct BindFirst {
    template<typename B>
    using Result = Foo<A, B>;
};

template<typename A>
struct Derived : Base<

        // error is here
        typename BindFirst<Foo, A>::Result

> {};

Which gives me error:

template argument for template template parameter must be a class template or type alias template

diralik
  • 6,391
  • 3
  • 28
  • 52

1 Answers1

2

The template Base expects a template as the first parameter but you attempt to pass a dependent type (indicated by typename), hence the error message. Moreover, the nested alias Result inside BindFirst is a template and therefore would require a template parameter for use with typename. So instead of

typename BindFirst<Foo, A>::Result

you have to tell the compiler that Result is in fact a template, using

BindFirst<Foo, A>::template Result

Live example

Henri Menke
  • 10,705
  • 1
  • 24
  • 42