summaryrefslogtreecommitdiff
path: root/lib/nes/common/utils.hh
blob: 460d0d5949c5bbfaecbbb03b360323fa3a9c25be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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