|
| 1 | +# get_allocator |
| 2 | +* execution[meta header] |
| 3 | +* cpo[meta id-type] |
| 4 | +* std[meta namespace] |
| 5 | +* cpp26[meta cpp] |
| 6 | + |
| 7 | +```cpp |
| 8 | +namespace std { |
| 9 | + struct get_allocator_t { unspecified }; |
| 10 | + constexpr get_allocator_t get_allocator{}; |
| 11 | +} |
| 12 | +``` |
| 13 | +* unspecified[italic] |
| 14 | +
|
| 15 | +## 概要 |
| 16 | +`get_allocator`は、[クエリ可能オブジェクト](queryable.md)からアロケータを取得する[クエリオブジェクト](queryable.md)である。 |
| 17 | +
|
| 18 | +コア定数式[`forwarding_query`](forwarding_query.md.nolink)`(get_allocator)`は`true`値を返す。 |
| 19 | +
|
| 20 | +
|
| 21 | +## 効果 |
| 22 | +式`get_allocator(env)`は下記と等価であり、説明専用コンセプト`simple-allocator`を満たす型の値となる。 |
| 23 | +
|
| 24 | +- 引数`env`がconst修飾された`cenv`を用いて、式`cenv.query(get_allocator)`が適格であること。 |
| 25 | +
|
| 26 | +```cpp |
| 27 | +template<class Alloc> |
| 28 | +concept simple-allocator = |
| 29 | + requires(Alloc alloc, size_t n) { |
| 30 | + { *alloc.allocate(n) } -> same_as<typename Alloc::value_type&>; |
| 31 | + { alloc.deallocate(alloc.allocate(n), n) }; |
| 32 | + } && |
| 33 | + copy_constructible<Alloc> && |
| 34 | + equality_comparable<Alloc>; |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | +## 例外 |
| 39 | +投げない |
| 40 | + |
| 41 | + |
| 42 | +## カスタマイゼーションポイント |
| 43 | +const修飾[クエリ可能オブジェクト](queryable.md)`env`に対して式`env.query(get_allocator)`が呼び出される。 |
| 44 | +このとき、`noexcept(cenv.query(get_allocator)) == true`であること。 |
| 45 | + |
| 46 | + |
| 47 | +## 例 |
| 48 | +```cpp |
| 49 | +#include <concepts> |
| 50 | +#include <memory> |
| 51 | +#include <execution> |
| 52 | +namespace ex = std::execution; |
| 53 | + |
| 54 | +int main() |
| 55 | +{ |
| 56 | + auto env = ex::prop(std::get_allocator, std::allocator<int>{}); |
| 57 | + |
| 58 | + auto alloc = std::get_allocator(env); |
| 59 | + static_assert(std::same_as<decltype(alloc), std::allocator<int>>); |
| 60 | +} |
| 61 | +``` |
| 62 | +* std::get_allocator[color ff0000] |
| 63 | +* ex::prop[link execution/prop.md] |
| 64 | +
|
| 65 | +### 出力 |
| 66 | +``` |
| 67 | +``` |
| 68 | +
|
| 69 | +
|
| 70 | +## バージョン |
| 71 | +### 言語 |
| 72 | +- C++26 |
| 73 | +
|
| 74 | +### 処理系 |
| 75 | +- [Clang](/implementation.md#clang): ?? |
| 76 | +- [GCC](/implementation.md#gcc): ?? |
| 77 | +- [ICC](/implementation.md#icc): ?? |
| 78 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 79 | +
|
| 80 | +
|
| 81 | +## 参照 |
| 82 | +- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html) |
0 commit comments