aboutsummaryrefslogtreecommitdiff
path: root/libk/types.h
blob: 3e728fb398f25b786a58a424d7723b1bba60839d (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
#pragma once

typedef unsigned short size_t;
typedef int ssize_t;

typedef unsigned char uint8_t;
constexpr uint8_t uint8_t_min = 0;
constexpr uint8_t uint8_t_max = 0xff;

typedef unsigned short uint16_t;
constexpr uint16_t uint16_t_min = 0;
constexpr uint16_t uint16_t_max = 0xffff;

typedef unsigned int uint32_t;
constexpr uint32_t uint32_t_min = 0;
constexpr uint32_t uint32_t_max = 0xffffffff;

typedef unsigned long long uint64_t;
constexpr uint64_t uint64_t_min = 0;
constexpr uint64_t uint64_t_max = 0xffffffffffffffff;

typedef char int8_t;
constexpr int8_t int8_t_max = uint8_t_max / 2;
constexpr int8_t int8_t_min = -int8_t_max - 1;

typedef short int16_t;
constexpr int16_t int16_t_max = uint16_t_max / 2;
constexpr int16_t int16_t_min = -int16_t_max - 1;

typedef int int32_t;
constexpr int32_t int32_t_max = uint32_t_max / 2;
constexpr int32_t int32_t_min = -int32_t_max - 1;

typedef long long int int64_t;
constexpr int64_t int64_t_max = uint64_t_max / 2;
constexpr int64_t int64_t_min = -int64_t_max - 1;

/* Type Traits */

template <class T, T v>
struct integral_constant {
  constexpr T operator()() const { return v; }
  constexpr operator T() const { return v; }
  static const T value = v;
};

/* is_same */
template <class T, class U>
struct is_same : integral_constant<bool, false> {};

template <class T>
struct is_same<T, T> : integral_constant<bool, true> {};

/* is_unsigned */
template <typename T>
struct is_unsigned : integral_constant<bool, (T{0} < static_cast<T>(-1))> {};

/* error enum concept */
template <typename T>
concept error_enum_t = (__is_enum(T) && requires { T::NoError; });