gpt4 book ai didi

c++ - 无法将 int 应用于 partial_apply 的结果

转载 作者:行者123 更新时间:2023-11-30 03:22:14 25 4
gpt4 key购买 nike

// 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)>;
}

我使用命令 clang++-5.0 -std=c++17 test_partial_apply.cc 编译了 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

Live Demo

关于c++ - 无法将 int 应用于 partial_apply 的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51298878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com