【发布时间】:2018-11-12 22:09:19
【问题描述】:
我有类Foo,它有两个模板参数A和B:
template<typename A, typename B>
struct Foo {};
我还有类Base,它有一个模板模板参数:
template<template<typename B> typename Foo>
struct Base {};
我想写 Derived 类,假设如下:
-
Derived有一个模板参数 (A) -
Derived扩展类Base -
Derived作为模板参数传递给Base类Foo,但有一个参数“currying” (A)
我该怎么做?
这是我的 (not working) 解决方案:
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
> {};
这给了我错误:
模板参数的模板参数必须是类模板或类型别名模板
【问题讨论】:
-
BindFirst<Foo, A>::template Result(不是typename,它是一个模板)。
标签: c++ templates metaprogramming currying