IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
mem_initializers.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/mem.hxx>
6#include <ice/mem_memory.hxx>
7
8namespace ice
9{
10
11 template<typename T, typename... Args>
12 auto mem_construct_at(void* memory_ptr, Args&&... args) noexcept -> T*
13 {
14 // TODO: Assert (align + size)
15 return new (memory_ptr) T{ ice::forward<Args>(args)... };
16 }
17
18 template<typename T, typename... Args>
19 auto mem_construct_at(ice::Memory memory, Args&&... args) noexcept -> T*
20 {
21 // TODO: Assert (align + size)
22 return mem_construct_at<T>(memory.location, ice::forward<Args>(args)...);
23 }
24
25 template<typename T>
26 auto mem_move_construct_at(void* memory_ptr, T&& other) noexcept -> T*
27 {
28 return new (memory_ptr) T{ ice::move(other) };
29 }
30
31 template<typename T>
32 auto mem_move_construct_at(ice::Memory memory, T&& other) noexcept -> T*
33 {
34 // TODO: Assert (align + size)
35 return mem_move_construct_at<T>(memory.location, ice::move(other));
36 }
37
38 template<typename T>
39 auto mem_copy_construct_at(ice::Memory memory, T const& other) noexcept -> T*
40 {
41 // TODO: Assert (align + size)
42 return new (memory.location) T{ other };
43 }
44
45 template<typename T>
47 {
48 // TODO: Assert (align + size)
49 T* target_mem = reinterpret_cast<T*>(memory.location);
50 for (ice::u64 idx = 0; idx < count; ++idx)
51 {
52 new (target_mem + idx) T{ };
53 }
54 return target_mem;
55 }
56
57 template<typename T>
58 auto mem_move_construct_n_at(ice::Memory memory, T* objects, ice::u64 count) noexcept -> T*
59 {
60 // TODO: Assert (align + size)
61 T* target_mem = reinterpret_cast<T*>(memory.location);
62 for (ice::u64 idx = 0; idx < count; ++idx)
63 {
64 new (target_mem + idx) T{ ice::move(objects[idx]) };
65 }
66 return target_mem;
67 }
68
69 template<typename T>
70 auto mem_move_n_to(T* target_objects, T* objects, ice::u64 count) noexcept -> T*
71 {
72 for (ice::u64 idx = 0; idx < count; ++idx)
73 {
74 target_objects[idx] = ice::move(objects[idx]);
75 }
76 return target_objects;
77 }
78
79 template<typename T>
80 auto mem_copy_construct_n_at(ice::Memory memory, T const* objects, ice::u64 count) noexcept -> T*
81 {
82 // TODO: Assert (align + size)
83 T* target_mem = reinterpret_cast<T*>(memory.location);
84 for (ice::u64 idx = 0; idx < count; ++idx)
85 {
86 new (target_mem + idx) T{ objects[idx] };
87 }
88 return target_mem;
89 }
90
91 template<typename T, typename ItT>
92 auto mem_copy_construct_it_at(ice::Memory memory, ItT begin, ItT end) noexcept -> T*
93 {
94 T* const target_mem = reinterpret_cast<T*>(memory.location);
95 ice::u64 idx = 0;
96 while (begin != end)
97 {
98 new (target_mem + idx) T{ *begin };
99 begin += 1;
100 idx += 1;
101 }
102 return target_mem;
103 }
104
105
106 template<typename T>
107 void mem_destruct_at(T* location) noexcept
108 {
109 location->~T();
110 }
111
112 template<typename T>
113 void mem_destruct_n_at(T* location, ice::u64 count) noexcept
114 {
115 for (ice::u64 idx = 0; idx < count; ++idx)
116 {
117 ice::mem_destruct_at(location + idx);
118 }
119 }
120
121} // namespace ice
SPDX-License-Identifier: MIT.
Definition array.hxx:12
auto mem_move_n_to(T *target_objects, T *objects, ice::u64 count) noexcept -> T *
Definition mem_initializers.hxx:70
auto mem_copy_construct_at(ice::Memory memory, T const &other) noexcept -> T *
Definition mem_initializers.hxx:39
auto mem_move_construct_at(void *memory_ptr, T &&other) noexcept -> T *
Definition mem_initializers.hxx:26
auto mem_move_construct_n_at(ice::Memory memory, T *objects, ice::u64 count) noexcept -> T *
Definition mem_initializers.hxx:58
void mem_destruct_n_at(T *location, ice::u64 count) noexcept
Definition mem_initializers.hxx:113
std::uint64_t u64
Definition types.hxx:27
auto mem_copy_construct_it_at(ice::Memory memory, ItT begin, ItT end) noexcept -> T *
Definition mem_initializers.hxx:92
auto mem_default_construct_n_at(ice::Memory memory, ice::u64 count) noexcept -> T *
Definition mem_initializers.hxx:46
auto mem_copy_construct_n_at(ice::Memory memory, T const *objects, ice::u64 count) noexcept -> T *
Definition mem_initializers.hxx:80
constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
Definition base.hxx:43
void mem_destruct_at(T *location) noexcept
Definition mem_initializers.hxx:107
auto mem_construct_at(void *memory_ptr, Args &&... args) noexcept -> T *
Definition mem_initializers.hxx:12
Definition mem_memory.hxx:13