【C++】map

1、定义

template<
    class Key,
    class T,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<std::pair<const Key, T>>
> class map;

namespace pmr {
    template<
        class Key,
        class T,
        class Compare = std::less<Key>
    > using map = std::map<Key, T, Compare,
                           std::pmr::polymorphic_allocator<std::pair<const Key, T>>>;
}

std::map 是一种有序关联容器,它包含具有唯一键的键值对。键之间以比较函数 Compare 排序。搜索、移除和插入操作拥有对数复杂度。map 通常实现为红黑树。

std::map 的迭代器以升序迭代各键,此升序由构造时所用的比较函数定义。

2、成员类型

3、构造函数

4、元素访问

4.1 at

带边界检查。

4.2 operator[]

5、查找

5.1 find

6、迭代器

6.1 end \ cend

posted @ 2024-07-16 07:13  NotReferenced  阅读(4)  评论(0编辑  收藏  举报