di 0.1.0
Loading...
Searching...
No Matches
allocate_one.h
Go to the documentation of this file.
1#pragma once
2
7#include "di/meta/vocab.h"
10
11namespace di::container {
12namespace detail {
13 template<typename T>
14 struct AllocateOneFunction {
15 template<concepts::Allocator Alloc>
16 constexpr auto operator()(Alloc& allocator) const -> meta::AllocatorResult<Alloc, T*> {
17 if consteval {
18 return std::allocator<T>().allocate(1);
19 }
20
21 return vocab::as_fallible(di::allocate(allocator, sizeof(T), alignof(T))) % [](AllocationResult<> result) {
22 return static_cast<T*>(result.data);
24 }
25 };
26}
27
28template<typename T>
29constexpr inline auto allocate_one = detail::AllocateOneFunction<T> {};
30}
31
32namespace di {
34}
Definition sequence.h:12
constexpr auto allocate_one
Definition allocate_one.h:29
meta::LikeExpected< decltype(di::allocate(util::declval< Alloc & >(), 0, 0)), T > AllocatorResult
Definition allocator.h:25
constexpr auto as_fallible
Definition as_fallible.h:26
constexpr auto try_infallible
Definition try_infallible.h:31
Definition any_storable.h:9
constexpr auto allocate
Definition allocate.h:26