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

typedef unsigned short size_t;
typedef int ssize_t;

typedef unsigned char uint8_t;

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

typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;

typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int int64_t;

/* in x86:
 * byte:  1 byte,   8 bits
 * word:  2 bytes, 16 bits
 * dword: 4 bytes, 32 bits
 * qword: 8 bytes, 64 bits
 * */
typedef uint16_t uword_t;
typedef int16_t word_t;

// 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))> {};