From 64ebfde8bcd6408e3b6925624e8680c314db6efc Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Thu, 6 Feb 2025 19:54:38 +0100 Subject: get rid of nasty stdlib --- lib/nes/common/utils.hh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/nes/common/utils.hh (limited to 'lib/nes/common/utils.hh') 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 + auto launder(T* p) -> T* + { + return __builtin_launder(p); + } + + template + auto copy(T const* src, T* dst, u32 const length) + { + for (auto i = u32{ 0 }; i < length; ++i) { dst[i] = src[i]; } + } + + template + auto min(T const a, T const b) + { + return a < b ? a : b; + } + + template + auto max(T const a, T const b) + { + return a > b ? a : b; + } + + template + auto swap(T& a, T& b) -> void + { + auto const tmp = a; + a = b; + b = tmp; + } +} // namespace nes \ No newline at end of file -- cgit v1.3.1