微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Microsoft Compiler 中宏导致的编译错误

如何解决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>);

并且在 GCCClang 中一切正常,但是 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 举报,一经查实,本站将立刻删除。