summaryrefslogtreecommitdiff
path: root/lib/nes/common/utils.hh
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-06 19:54:38 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-06 19:54:38 +0100
commit64ebfde8bcd6408e3b6925624e8680c314db6efc (patch)
treeb969314f909f7f16ef5acc63f90dca317a40850a /lib/nes/common/utils.hh
parentd060e3a50c987d10799ccc739bdbf9d7d7a13c10 (diff)
get rid of nasty stdlib
Diffstat (limited to 'lib/nes/common/utils.hh')
-rw-r--r--lib/nes/common/utils.hh38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/nes/common/utils.hh b/lib/nes/common/utils.hh
new file mode 100644
index 0000000..460d0d5
--- /dev/null
+++ b/lib/nes/common/utils.hh
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "nes/common/types.hh"
+
+namespace nes
+{
+ template<typename T>
+ auto launder(T* p) -> T*
+ {
+ return __builtin_launder(p);
+ }
+
+ template<typename T>
+ auto copy(T const* src, T* dst, u32 const length)
+ {
+ for (auto i = u32{ 0 }; i < length; ++i) { dst[i] = src[i]; }
+ }
+
+ template<typename T>
+ auto min(T const a, T const b)
+ {
+ return a < b ? a : b;
+ }
+
+ template<typename T>
+ auto max(T const a, T const b)
+ {
+ return a > b ? a : b;
+ }
+
+ template<typename T>
+ auto swap(T& a, T& b) -> void
+ {
+ auto const tmp = a;
+ a = b;
+ b = tmp;
+ }
+} // namespace nes \ No newline at end of file