std::set
STD:设置
Defined in header | | |
---|---|---|
template< class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> > class set; | (1) | |
namespace pmr { template <class Key, class Compare = std::less<Key>> using set = std::set<Key, Compare, std::pmr::polymorphic_allocator<Key>>; } | (2) | (since C++17) |
std::set
是一个关联容器,它包含一组类型为类型的唯一对象的排序集合。Key
使用键比较函数进行排序。Compare
搜索、删除和插入操作具有对数复杂度。集合通常实现为红黑树...
标准库在任何地方使用Compare
概念、唯一性是利用等价关系来确定的。用不精确的术语来说,有两个对象a
和b
如果两者之间的比较都不低于其他值,则被认为是等效的:!comp(a, b) && !comp(b, a)
...
std::set
满足…的要求Container
,,,AllocatorAwareContainer
,,,AssociativeContainer
和ReversibleContainer
...
成员类型
Member type | Definition |
---|---|
key_type | Key |
value_type | Key |
size_type | Unsigned integer type (usually std::size_t) |
difference_type | Signed integer type (usually std::ptrdiff_t) |
key_compare | Compare |
value_compare | Compare |
allocator_type | Allocator |
reference | Allocator::reference (until C++11) value_type& (since C++11) |
Allocator::reference | (until C++11) |
value_type& | (since C++11) |
const_reference | Allocator::const_reference (until C++11) const value_type& (since C++11) |
Allocator::const_reference | (until C++11) |
const value_type& | (since C++11) |
pointer | Allocator::pointer (until C++11) std::allocator_traits<Allocator>::pointer (since C++11) |
Allocator::pointer | (until C++11) |
std::allocator_traits<Allocator>::pointer | (since C++11) |
const_pointer | Allocator::const_pointer (until C++11) std::allocator_traits<Allocator>::const_pointer (since C++11) |
Allocator::const_pointer | (until C++11) |
std::allocator_traits<Allocator>::const_pointer | (since C++11) |
iterator | BidirectionalIterator (until C++11) Constant BidirectionalIterator (since C++11) |
BidirectionalIterator | (until C++11) |
Constant BidirectionalIterator | (since C++11) |
const_iterator | Constant bidirectional iterator |
reverse_iterator | std::reverse_iterator<iterator> |
const_reverse_iterator | std::reverse_iterator<const_iterator> |
node_type | a specialization of node handle representing a container node (since C++17) |
insert_return_type | type describing the result of inserting a node_type, a specialization of template <class Iterator, class NodeType> struct /*unspecified*/ { Iterator position; bool inserted; NodeType node; }; instantiated with template arguments iterator and node_type. (since C++17) |
成员函数
(constructor) | constructs the set (public member function) |
---|---|
(destructor) | destructs the set (public member function) |
operator= | assigns values to the container (public member function) |
get_allocator | returns the associated allocator (public member function) |
迭代器
BEGINCBEGIN将迭代器返回到开头%28的公共成员函数%29
End cend将迭代器返回到End%28公共成员函数%29
将反向迭代器返回到开头%28的公共成员函数%29
rend crend将反向迭代器返回到End%28公共成员函数%29
容量
空检查容器是否为空%28公共成员函数%29
Size返回元素数%28公共成员函数%29
马克斯[医]Size返回元素的最大可能数%28公共成员函数%29
修饰符
清除内容%28公共成员功能%29
插入元素或节点%28,因为C++17%29%28公共成员函数%29
嵌入%28C++11%29构造元素就地%28公共成员函数%29
座落[医]提示%28C++11%29使用提示%28公共成员函数%29就地构造元素
擦除元素%28公共成员函数%29
交换交换内容%28公共成员函数%29
提取%28C++17%29从容器中提取节点%28公共成员函数%29
从另一个容器合并%28C++17%29个连接节点%28公共成员函数%29
查找
Count返回匹配特定键的元素数%28公共成员函数%29
查找具有特定密钥%28公共成员函数%29的查找元素
平等[医]范围返回匹配特定键%28公共成员函数%29的元素的范围
较低[医]绑定将迭代器返回给第一个元素,不少于给定的键%28公共成员函数%29。
上层[医]绑定将迭代器返回给大于给定键%28公共成员函数%29的第一个元素。
观察员
键[医]COMP返回比较键%28公共成员函数%29的函数
价值[医]COMP返回比较值类型对象中键的函数。[医]类型%28公共成员功能%29
非会员职能
operator==operator!=operator | lexicographically compares the values in the set (function template) |
---|---|
std::swap(std::set) | specializes the std::swap algorithm (function template) |
注记
成员类型iterator
和const_iterator
可能是同一类型的别名。自iterator
可转换为const_iterator
,,,const_iterator
应在函数参数列表中使用,以避免违反“一个定义规则”。
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。