Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
new_alloc.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <type_traits>
5
6namespace clustering {
7
11template <typename T> class NewAllocator {
12public:
14 NewAllocator(std::size_t /*size*/) {}
15
16 NewAllocator(const NewAllocator &) = delete;
18
20 T *allocate() { return new T; }
21
23 void deallocate(T *ptr) { delete ptr; }
24
26 void reset() {
27 // Do nothing, because we don't have any state
28 }
29
31 bool isDeallocSupported() { return true; }
32};
33
34} // namespace clustering
NewAllocator(std::size_t)
Constructs the allocator; the count hint is ignored since allocations are individual.
Definition new_alloc.h:14
void reset()
No-op; the allocator holds no bulk state to rewind.
Definition new_alloc.h:26
bool isDeallocSupported()
Reports that per-element deallocate is supported (true for this allocator).
Definition new_alloc.h:31
NewAllocator & operator=(const NewAllocator &)=delete
NewAllocator(const NewAllocator &)=delete
void deallocate(T *ptr)
Frees a pointer previously returned by allocate.
Definition new_alloc.h:23
T * allocate()
Allocates one default-constructed T via new.
Definition new_alloc.h:20