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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With