13#include <unordered_map>
20hi_warning_ignore_msvc(26474);
22namespace hi::inline
v1 {
24[[nodiscard]]
bool equal_ptr(
auto *p1,
auto *p2)
noexcept
26 return static_cast<void *
>(p1) ==
static_cast<void *
>(p2);
29template<
typename T,
typename U>
30void memswap(T& dst, U& src)
32 static_assert(
sizeof(T) ==
sizeof(U),
"memswap requires both objects of equal size");
33 std::byte tmp[
sizeof(T)];
34 memcpy(tmp, &src,
sizeof(T));
35 memcpy(&src, &dst,
sizeof(U));
36 memcpy(&dst, tmp,
sizeof(T));
49template<
typename InputIt,
typename T>
52 hi_axiom(dst !=
nullptr);
53 return new (dst) T(*src);
60template<
typename InputIt,
typename T>
63 hi_axiom(src_first != dst_first);
64 hi_axiom(src_last >= src_first);
68 while (src != src_last) {
89 hi_axiom(src !=
nullptr);
90 hi_axiom(dst !=
nullptr);
109 hi_axiom(src_last >= src_first);
111 if (src_first < dst_first) {
112 auto dst_last = dst_first + (src_last - src_first);
116 while (src != src_first) {
120 }
else if (src_first > dst_first) {
121 auto src = src_first;
122 auto dst = dst_first;
123 while (src != src_last) {
143 hi_axiom(src_last >= src);
145 while (src != src_last) {
152template<
typename It,
typename... Args>
155 for (
auto it = first; it != last; ++it) {
173template<std::
unsigned_
integral T>
184template<std::
unsigned_
integral T>
191constexpr T *ceil(T *ptr,
std::size_t alignment)
noexcept
193 hilet aligned_byte_offset = ceil(
reinterpret_cast<uintptr_t
>(ptr),
static_cast<uintptr_t
>(alignment));
194 return reinterpret_cast<T *
>(aligned_byte_offset);
200 hilet aligned_byte_offset =
floor(
reinterpret_cast<uintptr_t
>(ptr),
static_cast<uintptr_t
>(alignment));
201 return reinterpret_cast<T *
>(aligned_byte_offset);
212 hi_axiom(ptr !=
nullptr);
213 return static_cast<char *
>(ptr) + distance;
224 hi_axiom(ptr !=
nullptr);
225 return static_cast<char const *
>(ptr) + distance;
232 while (i != v.end()) {
241template<
typename K,
typename T>
245 while (i != v.end()) {
246 if (i->second.expired()) {
254template<
typename K,
typename T>
258 while (i != v.end()) {
259 cleanupWeakPointers(i->second);
260 if (i->second.size() == 0) {
268template<
typename Value,
typename Map,
typename Key,
typename... Args>
273 hilet i = map.find(key);
274 if (i == map.end()) {
275 value = std::make_shared<Value>(std::forward<Args>(args)...);
276 map.insert_or_assign(key, value);
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
T * placement_copy(InputIt src, T *dst)
Copy an object to another memory locations.
Definition memory.hpp:50
void * advance_bytes(void *ptr, std::ptrdiff_t distance) noexcept
Advance a pointer by a number of bytes.
Definition memory.hpp:210
void construct(It first, It last, Args const &...args)
Construct a set of objects.
Definition memory.hpp:153
constexpr bool is_aligned(T *p)
Check if a pointer is properly aligned for the object it is pointing at.
Definition memory.hpp:163
void placement_move_within_array(T *src_first, T *src_last, T *dst_first)
Move an objects between two memory locations.
Definition memory.hpp:107
T * placement_move(T *src, T *dst)
Move an object between two memory locations.
Definition memory.hpp:87
Definition alignment.hpp:64