nngn
Loading...
Searching...
No Matches
base.h
Go to the documentation of this file.
1
32#ifndef NNGN_UTILS_ALLOC_BASE_H
33#define NNGN_UTILS_ALLOC_BASE_H
34
35#include <cstddef>
36
37namespace nngn {
38
40struct allocator_opts {
41 bool is_always_equal;
42};
43
49template<typename T, allocator_opts o> struct allocator_base {};
50
51template<typename T, allocator_opts o>
52bool operator==(const allocator_base<T, o>&, const allocator_base<T, o>&) {
53 return o.is_always_equal;
54}
55
56template<typename T, allocator_opts o>
57bool operator!=(const allocator_base<T, o>&, const allocator_base<T, o>&) {
58 return !o.is_always_equal;
59}
60
65template<typename T>
66using stateless_allocator = allocator_base<T, /*XXX*/allocator_opts{.is_always_equal = true}>;
67
72template<typename T>
73using stateful_allocator = allocator_base<T, /*XXX*/allocator_opts{.is_always_equal = false}>;
74
75namespace detail {
76
82template<typename A>
83static constexpr bool has_realloc =
84 requires(A a, typename A::pointer p, std::size_t n) {
85 a.reallocate(p, n);
86 };
87
93template<typename A, typename T>
94static constexpr bool has_typed_alloc =
95 requires(A a, typename A::pointer p, std::size_t n, T t) {
96 a.allocate(p, n, t);
97 };
98
99}
100
101}
102
103#endif
n
Definition: dump_lights.lua:5
a
Definition: input.lua:31
p
Definition: input.lua:29
#define T(f0, f1, f2)
static constexpr bool has_realloc
Checks whether an allocator supports memory relocation.
Definition: base.h:83
static constexpr bool has_typed_alloc
Checks whether an allocator supports typed memory allocations.
Definition: base.h:94
Definition: audio.cpp:7
constexpr bool operator!=(const T< R > &v0, const T< R > &v1)
Definition: vec.h:229
allocator_base< T, allocator_opts{.is_always_equal=false}> stateful_allocator
Base class for allocators that have state.
Definition: base.h:73
allocator_base< T, allocator_opts{.is_always_equal=true}> stateless_allocator
Base class for allocators that have no state.
Definition: base.h:66
constexpr bool operator==(const mat< CRTP, T, N > &m0, const mat< CRTP, T, N > &m1)
Definition: mat.h:57
bool is_always_equal
Definition: base.h:41