是std :: fill,std :: copy专用于std :: vector< bool&gt ;? [英] Are std::fill, std::copy specialized for std::vector<bool>?

查看:234
本文介绍了是std :: fill,std :: copy专用于std :: vector< bool&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在思考这个问题时,我开始怀疑 std :: copy()和/或 std :: fill 是专门的$ c> std :: vector< bool> 。

When thinking about this question I start to wondering if std::copy() and/or std::fill are specialized (I really mean optimized) for std::vector<bool>.

这是C ++标准所必需的,

Is this required by C++ standard or, perhaps, it is common approach by C++ std library vendors?

简单来说,我不知道是否下面的代码:

Simple speaking, I wonder to know if the following code:

std::vector<bool> v(10, false);
std::fill(v.begin(), v.end(), true);

以任何方式更好/不同:

is in any way better/different than that:

std::vector<bool> v(10, false);
for (auto it = v.begin(); it != v.end(); ++it) *it = true;

要非常严格 - 可以,让说: std :: fill< std :: vector< bool> :: iterator>()进入 std :: vector< bool> 的内部表示,而不是单个位?我假设让 std :: fill 的朋友 std :: vector< bool>

To be very strict - can, let say: std::fill<std::vector<bool>::iterator>() go into internal representation of std::vector<bool> and sets their entire bytes instead of single bits? I assume making std::fill friend of std::vector<bool> is not a big problem for library vendor?

[UPDATE]

下一个相关问题:我可以(或任何人:)假设 std :: vector< bool> ,如果不是专门的?这是C ++标准允许的吗?我知道这将是非便携式 - 但只是一个选定的std C ++库?假设我(或任何其他人)找到一种方式获得 std :: vector< bool> 私有部分。

Next related question: can I (or anybody else :) specialize such algorithms for let say std::vector<bool>, if not already specialized? Is this allowed by C++ standard? I know this will be non portable - but just for one selected std C++ library? Assuming I (or anybody else) find a way to get to std::vector<bool> private parts.

推荐答案

STD是仅标头库,它随您的编译器一起提供。您可以自己查看这些标头。对于GCC的向量< bool> impelemtation在 stl_bvector.h 。它可能是同一个文件,其他编译器。是的,有专门 fill (看看 __ fill_bvector )。

STD is headers only library and it is shipped with your compiler. You can look into those headers yourself. For GCC's vector<bool> impelemtation is in stl_bvector.h. It probably will be the same file for other compilers too. And yes, there is specialized fill (look near __fill_bvector).

这篇关于是std :: fill,std :: copy专用于std :: vector&lt; bool&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆