计算std :: vector <bool>

时间:2019-08-01 13:13:40

标签: c++ visual-c++ vector boolean

std::vector<bool>是否使用POPCNT指令来计算std::count算法的结果?

如果否,是否可以在不复制粘贴整个向量的情况下实现?为此,我需要访问实际上存储在该向量中的unsigned int值,可以吗?

如果有关系,我只需要VC ++ 2017解决方案。

1 个答案:

答案 0 :(得分:2)

per awaited item while the first one doesn't. Is this still going through the不幸没有为std::count使用popcnt(至少在GNU C ++标准库中)。

std::vector<bool>也不提供对其原始存储的访问,std::vector<bool>返回std::vector<bool>::data

另一种解决方案是使用voidboost::dynamic_bitset<>使用boost::dynamic_bitset<>::count指令,请参见assembly output

GNU C ++ popcnt是次最佳实现的,其大小为40个字节。 std::vector<bool>是32。