首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::vector<bool>

Defined in header <vector>

template<class Allocator> class vector<bool, Allocator>;

std::vector<bool>std::vector类型bool...

以何种方式std::vector<bool>使空间效率达到%28,以及是否在所有%29上优化都已定义了实现。一种可能的优化是将向量元素合并起来,使每个元素占用一个位,而不是只占用一个位。sizeof(bool)字节。

std::vector<bool>行为类似于std::vector,但为了提高空间效率,它:

  • 不一定将其元素存储为连续数组%28so&v[0] + n != &v[n]%29
  • 暴露类std::vector<bool>::reference作为访问单个位的方法。尤其是,此类的对象由operator[]按价值计算。
  • 不使用std::allocator_traits::construct构造位值。
  • 不能保证同一容器中的不同元素可以由不同的线程并发修改。

成员类型

Member type

Definition

value_type

bool

allocator_type

Allocator

size_type

implementation-defined

difference_type

implementation-defined

reference

proxy class representing a reference to a single bool (class)

const_reference

bool

pointer

implementation-defined

const_pointer

implementation-defined

iterator

implementation-defined

const_iterator

implementation-defined

reverse_iterator

std::reverse_iterator<iterator>

const_reverse_iterator

std::reverse_iterator<const_iterator>

成员函数

(constructor)

constructs the vector (public member function of std::vector)

(destructor)

destructs the vector (public member function of std::vector)

operator=

assigns values to the container (public member function of std::vector)

assign

assigns values to the container (public member function of std::vector)

get_allocator

returns the associated allocator (public member function of std::vector)

元素存取

在访问指定元素时,使用边界检查%28公共成员函数::Vectory%29

操作者。[[访问指定元素%28 STD的公共成员函数::向量%29

前端访问STD的第一个元素%28公共成员函数::向量%29

反向访问std的最后一个元素%28公共成员函数::Vectory%29

迭代器

BEGINCBEGIN将一个迭代器返回给std::Vectory%29的起始%28公共成员函数

End cend将迭代器返回给std::Vectorent%29的End%28公共成员函数。

rBEGINCRBEGIN将反向迭代器返回到std::Vectory%29的起始%28公共成员函数

rend crend将反向迭代器返回给std::Vectory%29的结束%28公共成员函数。

容量

空检查容器是否为std::Vectory%29的空%28公共成员函数

Size返回STD::Vectory%29的元素数%28公共成员函数

马克斯[医]Size返回最大可能的元素数%28公共成员函数的std::向量%29

储备储备储备%28性病公共成员功能::矢量%29

容量返回当前分配的std的存储%28公共成员函数中可以保存的元素数::VIDVERY%29

修饰符

清除STD的内容%28公共成员功能::载体%29

插入STD的插入元素%28公共成员函数::向量%29

嵌入%28自C++14%29构造元素inplace%28公共成员函数的std::向量%29

擦除元素%28的STD::向量%29的公共成员功能

推[医]Back向std::Vectory%29的末尾%28公共成员函数中添加一个元素

座落[医]Back%28C++14%29在std::vectorc%29的结尾处构造元素

波普[医]Back移除std::Vectory%29的最后一个元素%28公共成员函数

调整大小可更改std::Vectory%29的存储元素数%28公共成员函数

交换交换STD的内容%28公共成员函数::向量%29

矢量<bool>特定修饰符

翻转所有位数%28公共成员函数%29

互换静态第二阶段性病::向量<bool>*参考资料%28公共静态成员函数%29

非会员职能

operator==operator!=operator<operator<=operator>operator>=

lexicographically compares the values in the vector (function template)

std::swap(std::vector)

specializes the std::swap algorithm (function template)

帮助者类

std::hash<std::vector<bool>> (C++11)

hash support for std::vector<bool> (class template specialization)

注记

如果在编译时已知位集的大小,std::bitset可以使用,它提供了一组更丰富的成员函数。此外,助推::动态[医]位集作为替代物而存在std::vector<bool>...

因为它的表达可以通过优化,std::vector<bool>不一定满足所有ContainerSequenceContainer所需经费。例如,因为std::vector<bool>::iterator是实现定义的,它可能无法满足ForwardIterator要求。使用算法,例如std::search需要ForwardIterator斯可能导致编译时或运行时错误...

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券