-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd.h
103 lines (74 loc) · 1.89 KB
/
std.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef TL_STD_H
#define TL_STD_H
#include "config.h"
#include "platform.h"
#include "cstdint.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h> // We include assert.h in order to override it
TL_BEGIN_C
//#define memalloc malloc
TL_INLINE void* memrealloc(void* p, usize news, usize olds) {
TL_UNUSED(olds);
return realloc(p, news);
}
//#define memfree free
//TL_API void* memalloc(size_t s);
//TL_API void* memrealloc(void* p, size_t news, size_t olds);
//TL_API void memfree(void* p);
void tl_std_init();
TL_API void panic();
TL_API u64 tl_get_ticks();
//TL_API void tl_crypto_rand(void* data, u32 amount);
#define TL_TIME(name, c) u64 name = tl_get_ticks(); c; name = tl_get_ticks() - name;
// It's not certain that the assert is declared in a compatible way in assert.h
#ifdef assert
# undef assert
#endif
#ifdef NDEBUG
#define assert(e) ((void)0)
#else
void assert_fail(char const* expr, char const* file, int line);
#define assert(e) if (!(e)) assert_fail(#e, __FILE__, __LINE__); else (void)0
#endif
TL_END_C
#if TL_CPP
#define TL_NON_COPYABLE(name) \
name(name const&) = delete; \
name& operator=(name const&) = delete
#define TL_MOVABLE(name) \
name(name&&) = default; \
name& operator=(name&&) = default
#define TL_NON_MOVABLE(name) \
name(name&&) = delete; \
name& operator=(name&&) = delete
#define TL_DEFAULT_CTORS(name) \
name() = default; \
TL_MOVABLE(name); \
TL_NON_COPYABLE(name);
namespace tl {
template<typename T>
T max(T const& a, T const& b) {
return a < b ? b : a;
}
template<typename T>
T min(T const& a, T const& b) {
return a < b ? a : b;
}
struct non_null {};
template<typename F>
inline u64 timer(F f) {
u64 start = tl_get_ticks();
f();
return tl_get_ticks() - start;
}
}
inline void* operator new(size_t, void* p, tl::non_null) {
TL_ASSUME_NOT_NULL(p);
return p;
}
#endif
#if TL_WINDOWS
# include "windows/std_inline.h"
#endif
#endif // TL_STD_H