C++ set get_allocator()

30 Aug 2024 | 3 分钟阅读

C++ set 的 get_allocator() 函数用于返回分配器对象的副本,该对象用于构造 set 容器。

语法

参数

返回值

返回与 set 容器关联的分配器。

复杂度

常量。

迭代器有效性

无变化。

数据竞争

容器被访问。

并发访问 set 的元素是安全的。

异常安全

此函数从不抛出异常。

示例 1

让我们看一个简单的例子

输出

Allocated size = 32

示例 2

让我们看一个简单的例子

输出

The allocated array contains: 10 20 30 40 50

示例 3

让我们看一个简单的例子,检查分配器是否可互换。

输出

The number of integers that can be allocated
before free memory is exhausted: 461168601842738790.

The number of doubles that can be allocated
before free memory is exhausted: 461168601842738790.

The allocators are interchangeable.

示例 4

让我们看一个简单的例子

输出

42, 43

下一主题Set operator==