我做错了什么还是微软std::popcount
对 Visual Studio 16.6.0 版本的支持中断了?
我正在使用 Microsoft Visual Studio 16.6.0,将 C++ 语言标准设置为Preview - Features from the Latest C++ Working Draft (std:c++latest)并尝试从 cppreference 编译 popcount 示例代码:
#include <bit>
#include <bitset>
#include <cstdint>
#include <initializer_list>
#include <iostream>
int main()
{
for (std::uint8_t i : { 0, 0b11111111, 0b00011101 }) {
std::cout << "popcount(0b" << std::bitset<8>(i) << ") = "
<< std::popcount(i) << '\n';
}
}
尽管 cppreference 声明自 16.5 版和 MSVC 16.6 定义功能宏以来已支持位操作 ( P0553R4 ) ,但上述代码仍会出现以下错误:__cpp_lib_bitops
Error C3861 'popcount': identifier not found ConsoleApplication3 C:\Users\rsjaf\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp 22
Message see declaration of 'std' ConsoleApplication3 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\iostream 19
Error (active) E0135 namespace "std" has no member "popcount" ConsoleApplication3 C:\Users\rsjaf\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp 22
Error C2039 'popcount': is not a member of 'std' ConsoleApplication3 C:\Users\rsjaf\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp 22
当我查看bit
标题时,我确实看到了一个模板popcount
,但它似乎对我的应用程序被禁用。