unordered_set容器函数说明

构造函数

  • unordered_set:构造一个空的unordered_set容器。
  • unordered_set(const unordered_set& other):拷贝构造函数,构造一个unordered_set容器,并用另一个unordered_set容器的副本初始化。
  • unordered_set(unordered_set&& other) noexcept:移动构造函数,构造一个unordered_set容器,并用另一个unordered_set容器的元素初始化,另一个容器的内容将被移动。
  • unordered_set(size_type count):构造一个包含count个元素的unordered_set容器。
  • unordered_set(size_type count, const key_type& key, const hasher& hash_fn = hasher(), const key_equal& equal_fn = key_equal()):构造一个包含count个重复的key元素的unordered_set容器。
  • template< class InputIt > unordered_set(InputIt first, InputIt last, size_type count = 0, const hasher& hash_fn = hasher(), const key_equal& equal_fn = key_equal()):构造一个包含范围在[first, last)之间的元素的unordered_set容器。

迭代器

  • begin():返回一个指向unordered_set容器第一个元素的迭代器。
  • end():返回一个指向unordered_set容器尾元素下一个位置的迭代器。
  • cbegin() const:返回一个指向unordered_set容器第一个元素的const迭代器。
  • cend() const:返回一个指向unordered_set容器尾元素下一个位置的const迭代器。

容量

  • empty() const:返回一个bool值,指示unordered_set容器是否为空。
  • size() const:返回unordered_set容器中元素的数量。
  • max_size() const:返回unordered_set容器可以容纳的最大元素数。

修改器

  • insert(const value_type& value):将元素value插入unordered_set容器中。
  • insert(value_type&& value):将元素value插入unordered_set容器中,使用移动语义。
  • insert(InputIt first, InputIt last):插入来自范围[first, last)的元素到unordered_set容器中。
  • insert(std::initializer_list<value_type> ilist):从initializer_list中插入元素到unordered_set容器中。
  • emplace(Args&&... args):通过参数args构造元素并将其插入到unordered_set容器中。
  • erase(const_iterator position):从unordered_set容器中删除迭代器position所指向的元素。
  • erase(const key_type& key):从unordered_set容器中删除所有等于key的元素。
  • erase(first, last):从unordered_set容器中删除范围[first, last)的元素。
  • clear():从unordered_set容器中删除所有元素。

查找

  • find(const key_type& key):返回指向键值为key的元素的迭代器。如果未找到key,则返回end迭代器。
  • count(const key_type& key):统计键为key的元素个数,返回值为0或1,因为该容器不允许有重复元素。
  • equal_range(const key_type& key):返回键值等于key的元素范围,返回值为一个pair,其两个成员都是迭代器类型,表示范围的起始位置和结束位置。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呆先森HIT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值