namespace std没有成员std :: invoke_result_t

时间:2018-01-10 15:00:05

标签: c++ visual-studio-code clang std c++17

由于个人原因,我最近从MSVS切换到VS Code,而我的编译器现在是最新的Clang。

我遇到了一些麻烦(例如,我不能写typename O = ...,现在我必须写typename O = typename ...),但所有这些都很小并且很容易修复。除了一个。

我不知道原因,但编译器找不到std::invoke_result_tstd::invoke_result<>::type。令人厌恶的是,特别是因为IntelliSense很容易找到它。

这是错误日志:

{"Workspace" directory}/Untitled-1.cpp:5:54: error: no template named 'invoke_result_t' in namespace 'std'; did you mean '_Invoke_result_t'?
template<typename I, typename FTy, typename O = std::invoke_result_t<std::function<FTy>, I>>
                                                ~~~~~^~~~~~~~~~~~~~~
                                                     _Invoke_result_t
{MSVS Installation directory}\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include\type_traits:1832:2: note: '_Invoke_result_t' declared here
        using _Invoke_result_t = typename _Invoke_traits<void, _Callable, _Args...>::type;
        ^
1 error generated.

如果我使用提供的std::_Invoke_result_t而不是普通的,那么一切都会编译并按原样运行。

此外,每次编译包含std::cout的代码时,编译器都会写入一些本地定义的符号(诚实地说是_CxxThrowException和_std_terminate),这些符号被导入到函数中。

有没有办法解决所有这些麻烦?哪些是错误,哪些是功能?我听说,VS C ++库没有达到ISO标准,这可能是我麻烦的原因吗?

1 个答案:

答案 0 :(得分:1)

std::invoke_result是C ++ 17的一部分,请确保编译器具有-std=c++17选项。

此外,

#include <type_traits>

如果您使用的是clang或旧版本的c ++,请考虑使用std::result_of