分配但不使用分配器的标准库设施

Standard library facilities which allocate but don't use an Allocator

在大多数 C++ 标准库分配内存的地方,用户可以通过提供满足 Allocator requirements 的 class 来自定义它。例如,几乎所有容器都采用分配器模板参数,并且 std::allocate_shared returns 一个 shared_ptr 其包含的元素和控制块都通过提供的分配器进行分配。

然而,有几个地方标准库可以(可能)分配内存,但不提供 Allocator 支持。我能想到的是:

问题:

并非详尽列表。

  • <stdexcept>中的所有内容,需要分配内存来存储消息字符串。
  • 标准 pool/monotonic 内存资源 类 显然分配内存,但它们是从另一个内存资源而不是分配器执行的,因此它们在技术上符合您的描述。
  • boyer_moore_searcherboyer_moore_horspool_searcher.
  • 几个 <algorithm> 算法试图获得额外的内存(例如,stable_partitionstable_sort)并且所有并行算法(不管 header)可能需要额外的内存。
  • 文件系统库中的许多东西:
    • path;那个曾经在内部使用默认分配器,但看起来最新的草案删除了该要求,尽管它似乎仍然是意图。
    • directory_iteratorrecursive_directory_iterator
    • 一些可以构造临时 paths .
    • 的文件系统操作
  • basic_­regex.
  • threadasync.
  • packaged_task,在 C++17 中删除了分配器支持。
  • promise 需要在某处放置共享状态。
  • iostreams.
  • 许多事情 hard-coded 使用默认分配器:
    • error_code::message()error_condition::message()error_category::message():这些 return 一个 string,所以只有默认分配器。
    • bitset 的流插入运算符名义上使用默认分配器调用 to_string,但实际上没有 high-quality 实现会这样做。
    • to_stringto_wstring 自由函数分别为 return std::string/std::wstring;没有机会指定您自己的分配器。显然 string 的 user-defined 文字(例如 "foo"s)也没有自定义分配器支持。
    • <locale> 中有几个方面具有成员函数 returning std::stringstd::basic_string<charT>,即使用默认分配器(例如,numpunct), 或者只接受 basic_string<charT> (例如, money_get).
    • <random> 中的各种类型使用带有默认分配器的 vector

If anybody knows, what are the reasons for not providing allocator support in any, and removing it from function?

any 的分配器支持是 unimplementable. function's allocator support is poorly specified and plagued with issues