c++ - 无法将 int 应用于 partial_apply 的结果
问题描述
// partial_apply.hpp
template <template <class...> class Op, class ...Ts>
struct partial_apply {
template <class ...Args> using type = Op<Ts..., Args...>;
};
# define PARTIAL_APPLY_T(OP, ...) typename partial_apply<OP, ##__VA_ARGS__>::template type
// test_partial_apply.cc
#include "partial_apply.hpp"
template <class ...Ts> struct A {};
template <template <class...> class Op> using apply_int = Op<int>;
int main() {
using type = apply_int<PARTIAL_APPLY_T(A)>;
}
我使用发出以下错误的test_partial_apply.cc
命令进行编译:clang++-5.0 -std=c++17 test_partial_apply.cc
test_partial_apply.cc:8:28: error: expected an identifier or template-id after '::'
using type = apply_int<PARTIAL_APPLY_T(A)>;
^~~~~~~~~~~~~~~~~~
./../include/partial_apply.hpp:9:78: note: expanded from macro 'PARTIAL_APPLY_T'
# define PARTIAL_APPLY_T(OP, ...) typename partial_apply<OP, ##__VA_ARGS__>::template type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
test_partial_apply.cc:8:28: error: expected a type
./../include/partial_apply.hpp:9:78: note: expanded from macro 'PARTIAL_APPLY_T'
# define PARTIAL_APPLY_T(OP, ...) typename partial_apply<OP, ##__VA_ARGS__>::template type
^
2 errors generated.
解决方案
typename
仅当它确实是一种类型时才使用消歧器。不指定模板参数template <class ...Args> using type = Op<Ts..., Args...>;
不是类型。
删除typename
,它应该可以工作:
# define PARTIAL_APPLY_T(OP, ...) partial_apply<OP, ##__VA_ARGS__>::template type
推荐阅读
- python - 如何组合(合并)不同的回归模型
- python - 在python中将图像添加到星形图案打印
- javascript - 总结 Eloquent JavaScript 第 5 章中的“reduce”
- python - 有什么用| 以下命令中的运算符?
- java - HikariPoolInitializationException:初始化池失败:用户'root'@'localhost'的访问被拒绝(使用密码:是)
- git - git merge 相当于 git rebase --onto
- python - 在 Azure 函数中安装包时出错 (Visual Studio)
- wpf - 将标题标题设置为 xamdatagrid?
- matlab - 为什么 iFFT(FFT(S)) 不返回 S?
- node.js - 节点版本 将 React 应用程序部署到 GCP 时出现问题