首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能将int应用于partial_apply的结果

不能将int应用于partial_apply的结果
EN

Stack Overflow用户
提问于 2018-07-12 06:43:28
回答 1查看 53关注 0票数 1
代码语言:javascript
复制
// 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,它发出了以下错误:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-12 06:53:30

只有在确实是类型时才使用typename消歧器。没有指定模板参数,template <class ...Args> using type = Op<Ts..., Args...>;就不是一种类型。

删除typename,它应该能工作:

代码语言:javascript
复制
# define PARTIAL_APPLY_T(OP, ...) partial_apply<OP, ##__VA_ARGS__>::template type

现场演示

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51298878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档