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 (将#修改为@)