如何解决Microsoft Compiler 中宏导致的编译错误
MSVC 似乎不喜欢我得到的基于宏的解决方案 here 将函数模板包装在函数对象中。
宏是
#define FUNCTORIZE(func) [](auto&&... val) \
noexcept(noexcept(func(std::forward<decltype(val)>(val)...))) -> decltype(auto) \
{return func(std::forward<decltype(val)>(val)...);}
像这样使用(例如)
template <std::size_t N>
inline constexpr auto get = FUNCTORIZE(std::get<N>);
std::transform(v.begin(),v.end(),w.begin(),get<1>);
并且在 GCC 和 Clang 中一切正常,但是 MSVC errors like this:
<source>(12): error C2760: Syntax error: unexpected token 'identifier',expected ')'
<source>(18): note: see reference to variable template 'const auto get<1>' being compiled
Compiler returned: 2
- 可能我只需要添加一些编译器标志(而不是指定比 C++17 更新的标准的标志)?
- 以不同的方式编写宏会有帮助吗?
- 我可以使用 MSVC 在 C++17 中使用该宏吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。