📜  C++库-

📅  最后修改于: 2020-12-15 04:35:23             🧑  作者: Mango


介绍

集合是一个关联容器,其中包含一组排序的键类型的唯一对象。每个元素只能出现一次,因此不允许重复。

关联容器有四种:set,multiset,map和multimap。

集合中元素的值不能在容器中一次修改,即,元素始终为const。但是可以将它们插入容器或从容器中取出。

集合容器在通过键访问单个元素方面通常比unordered_set容器慢,但是它们允许基于子集的顺序直接迭代子集。

定义

下面是头文件中std :: set的定义

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

参量

  • -包含的元素的类型。

    键可以由任何其他数据类型(包括用户定义的类型)代替。

会员类型

成员函数可以将以下成员类型用作参数或返回类型。

Sr.No. Member types Definition
1 key_type Key
2 value_type Key
3 reference Allocator::reference

value_type&

4 const_reference Allocator::const_reference

const value_type&

5 pointer Allocator::pointer

std::allocator_traits::pointer

6 const_pointer Allocator::const_pointer

std::allocator_traits::const_pointer

7 iterator BidirectionalIterator
8 const_iterator constant BidirectionalIterator
9 reverse_iterator std::reverse_iterator
10 const_reverse_iterator std::reverse_iterator
11 size_type Unsigned Integer Type (std::size_t)
12 difference_type Signed Integer Type (std::ptrdiff_t)
13 key_compare Compare
14 value_compare Compare
15 allocator_type Allocator

中的功能

以下是标头中所有方法的列表。

会员功能

默认会员功能

Sr.No. Method & Description
1 Default constructor

Constructs the set container.

2 Range constructor

Constructs the set container with contents of the range.

3 Copy constructor

Constructs the set container with the copy of other set.

4 Move constructor

Constructs the set container with the contents of other set using move semantics.

5 Initializer-list constructor

Constructs the set container with contents of the inializer list.

6 (destructor)

Destructs the set container.

7 operator=

Assigns values to the set container.

Sr.No. Method & Description
1 set::begin

Returns the iterator to beginning.

2 set::cbegin

Returns the const iterator to beginning.

3 set::end

Returns the iterator to end.

4 set::cend

Returns the const iterator to end.

5 set::rbegin

Returns the reverse iterator to reverse beginning.

6 set::crbegin

Return const reverse iterator to reverse beginning.

7 set::rend

Returns the reverse iterator to reverse end.

8 set::crend

Returns the const reverse iterator to reverse end.

容量

Sr.No. Method & Description
1 set::empty

Returns wheteher the set container is empty.

2 set::size

Returns the number of elements in the set container.

3 set::max_size

Returns the maximum number of elements that the set container can hold.

修饰语

Sr.No. Method & Description
1 set::clear

Removes all elements from the set container.

2 set::insert

Inserts new element in the set container.

3 set::emplace

Inserts new element in the set, if its unique.

4 set::emplace_hint

Inserts new element in the set, if its unique, with a hint on the inserting position.

5 set::erase

Removes either a single element or a range of elements from the set container.

6 set::swap

Exchanges the content of the container by the content of another set container of the same type.

抬头

Sr.No. Method & Description
1 set::count

Returns the number of elements with matching value in the set container.

2 set::find

Searches the set container for value and returns an iterator to it if found, else returns an iterator to set::end.

3 set::lower_bound

Returns an iterator pointing to the first element in the set container which is not considered to go before value.

4 set::upper_bound

Returns an iterator pointing to the first element in the set container which is considered to go after value.

5 set::equal_range

Returns the bounds of a range that includes all the elements in the set container that are equivalent to value.

观察者

Sr.No. Method & Description
1 set::key_comp

Returns a copy of the comparison object used by the set container.

2 set::value_comp

Returns a copy of the comparison object used by the set container.

分配者

Sr.No. Method & Description
1 set::get_allocator

Returns a copy of the allocator object associated with the set container.