c++11 标准模板(STL)(std::multiset)(四)

定义于头文件 <set>
template<

    class Key,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<Key>

> class multiset;
(1)
namespace pmr {

    template <class Key, class Compare = std::less<Key>>
    using multiset = std::multiset<Key, Compare,
                                   std::pmr::polymorphic_allocator<Key>>;

}
(2)(C++17 起)

std::multiset 是含有 Key 类型对象有序集的容器。不同于 set ,它允许多个关键拥有等价的值。用关键比较函数 Compare 进行排序。搜索、插入和移除操作拥有对数复杂度。

在标准库使用比较 (Compare) 概念的每处,都用描述于比较 (Compare) 的等价关系确定等价性。不精确地说,若二个对象 a 和 b 互不比较小于对方: !comp(a, b) && !comp(b, a) ,则认为它们等价。

比较等价的元素顺序是插入顺序,而且不会更改。(C++11 起)
 

迭代器

返回指向容器第一个元素的迭代器

std::multiset<Key,Compare,Allocator>::begin, 
std::multiset<Key,Compare,Allocator>::cbegin

iterator begin();

(C++11 前)

iterator begin() noexcept;

(C++11 起)

const_iterator begin() const;

(C++11 前)

const_iterator begin() const noexcept;

(C++11 起)

const_iterator cbegin() const noexcept;

(C++11 起)

返回指向容器首元素的迭代器。

若容器为空,则返回的迭代器将等于 end() 。

参数

(无)

返回值

指向首元素的迭代器。

复杂度

常数。

注意

因为 iteratorconst_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭代器修改容器元素。

返回指向容器尾端的迭代器

std::multiset<Key,Compare,Allocator>::end, 
std::multiset<Key,Compare,Allocator>::cend

iterator end();

(C++11 前)

iterator end() noexcept;

(C++11 起)

const_iterator end() const;

(C++11 前)

const_iterator end() const noexcept;

(C++11 起)

const_iterator cend() const noexcept;

(C++11 起)

返回指向容器末元素后一元素的迭代器。

此元素表现为占位符;试图访问它导致未定义行为。

参数

(无)

返回值

指向后随最后元素的迭代器。

复杂度

常数。

注意

因为 iteratorconst_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭代器修改容器元素。

返回指向容器最后元素的逆向迭代器

std::multiset<Key,Compare,Allocator>::rbegin,
std::multiset<Key,Compare,Allocator>::crbegin

reverse_iterator rbegin();

(C++11 前)

reverse_iterator rbegin() noexcept;

(C++11 起)

const_reverse_iterator rbegin() const;

(C++11 前)

const_reverse_iterator rbegin() const noexcept;

(C++11 起)

const_reverse_iterator crbegin() const noexcept;

(C++11 起)

返回指向逆向容器首元素的逆向迭代器。它对应非逆向容器的末元素。

参数

(无)

返回值

指向首元素的逆向迭代器。

复杂度

常数。

注意

因为 iteratorconst_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭代器修改容器元素。

 

返回指向前端的逆向迭代器

std::multiset<Key,Compare,Allocator>::rend, 
std::multiset<Key,Compare,Allocator>::crend

reverse_iterator rend();

(C++11 前)

reverse_iterator rend() noexcept;

(C++11 起)

const_reverse_iterator rend() const;

(C++11 前)

const_reverse_iterator rend() const noexcept;

(C++11 起)

const_reverse_iterator crend() const noexcept;

(C++11 起)

返回指向逆向容器末元素后一元素的逆向迭代器。它对应非逆向容器首元素的前一元素。此元素表现为占位符,试图访问它导致未定义行为。

参数

(无)

返回值

指向末元素后一元素的逆向迭代器。

复杂度

常数。

注意

因为 iteratorconst_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭代器修改容器元素。

 

调用示例

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值