summaryrefslogtreecommitdiff
path: root/lib/nes/common/utils.hh
diff options
context:
space:
mode:
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