summaryrefslogtreecommitdiff
path: root/deimos/core/std.h
blob: 601bfb9092e3a6b31a49859019d49abcb17aba95 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once

using uint8_t   = unsigned char;
using uint16_t  = unsigned short;
using uint32_t  = unsigned int;
using uint64_t  = unsigned long long;

using int8_t    = char;
using int16_t   = short;
using int32_t   = int;
using int64_t   = long long;

using size_t    = uint64_t;

static_assert(sizeof(size_t) == sizeof(void*), "size_t should be pointer size");

namespace std
{

template<typename T> constexpr bool is_trivially_destructible_v = __is_trivially_destructible(T);

template<typename U, typename V> constexpr bool _is_same_helper = false;
template<typename T> constexpr bool _is_same_helper<T, T> = true;
template<typename U, typename V> concept same_as = _is_same_helper<U, V> && _is_same_helper<V, U>;

template<typename T> struct remove_reference { using type = T; };
template<typename T> struct remove_reference<T&> { using type = T; };
template<typename T> struct remove_reference<T&&> { using type = T; };
template<typename T> using remove_reference_t = remove_reference<T>::type;

template<typename T>
constexpr remove_reference_t<T>&& move(T&& r) noexcept
{
    return static_cast<remove_reference_t<T>&&>(r);
}

template<typename T>
constexpr T&& forward(remove_reference_t<T>& r) noexcept
{
    return static_cast<T&&>(r);
}

template<typename T>
constexpr T&& forward(remove_reference_t<T>&& r) noexcept // NOLINT
{
    return static_cast<T&&>(r);
}

template<typename T, typename U>
constexpr T exchange(T& obj, U&& new_value)
{
    T old_value = std::move(obj);
    obj = std::forward<U>(new_value);
    return old_value;
}

enum __attribute__((__may_alias__)) byte : uint8_t {};
static_assert(sizeof(byte) == 1, "");

} // namespace std

static_assert(std::same_as<int, int>, "");
static_assert(!std::same_as<int, void>, "");

static_assert(std::same_as<std::remove_reference_t<int>, int>, "");
static_assert(std::same_as<std::remove_reference_t<int&>, int>, "");
static_assert(std::same_as<std::remove_reference_t<int&&>, int>, "");

constexpr void* operator new(size_t, void* ptr)
{
    return ptr;
}