Skip to content

Latest commit

 

History

History
82 lines (61 loc) · 2.02 KB

get_allocator.md

File metadata and controls

82 lines (61 loc) · 2.02 KB

get_allocator

  • execution[meta header]
  • cpo[meta id-type]
  • std[meta namespace]
  • cpp26[meta cpp]
namespace std {
  struct get_allocator_t { unspecified };
  constexpr get_allocator_t get_allocator{};
}
  • unspecified[italic]

概要

get_allocatorは、クエリ可能オブジェクトからアロケータを取得するクエリオブジェクトである。

コア定数式forwarding_query(get_allocator)true値を返す。

効果

呼び出し式get_allocator(env)は下記と等価であり、適格であれば説明専用コンセプトsimple-allocatorを満たす型の値となる。

  • 引数envがconst修飾されたcenvを用いて、式cenv.query(get_allocator)
template<class Alloc>
concept simple-allocator =
  requires(Alloc alloc, size_t n) {
    { *alloc.allocate(n) } -> same_as<typename Alloc::value_type&>;
    { alloc.deallocate(alloc.allocate(n), n) };
  } &&
  copy_constructible<Alloc> &&
  equality_comparable<Alloc>;

例外

投げない

カスタマイゼーションポイント

const修飾クエリ可能オブジェクトcenvに対して式cenv.query(get_allocator)が呼び出される。 このとき、noexcept(cenv.query(get_allocator)) == trueであること。

#include <concepts>
#include <memory>
#include <execution>
namespace ex = std::execution;

int main()
{
  auto env = ex::prop(std::get_allocator, std::allocator<int>{});

  auto alloc = std::get_allocator(env);
  static_assert(std::same_as<decltype(alloc), std::allocator<int>>);
}
  • std::get_allocator[color ff0000]
  • ex::prop[link execution/prop.md]

出力

バージョン

言語

  • C++26

処理系

参照