-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManapiUtils.hpp
110 lines (101 loc) · 3.85 KB
/
ManapiUtils.hpp
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
104
105
106
107
108
109
110
#pragma once
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <list>
#include <forward_list>
#include <typeinfo>
//#include "./extensions/jemallocator.hpp"
#define REQ(_x) manapi::net::http::request &_x
#define RESP(_x) manapi::net::http::response &_x
#define HANDLER(_req, _resp) (REQ(_req), RESP(_resp))
namespace manapi::memory {
template<typename T>
constexpr T *alloc (std::size_t size) {
auto p = static_cast<T *> (::malloc(size));
if (!p) { throw std::bad_alloc(); }
return p;
}
inline void free (void *p) {
::free(p);
}
template<typename T>
constexpr T *realloc (T *n, std::size_t size) {
auto p = static_cast<T *> (::realloc(n, size));
if (!p) { throw std::bad_alloc(); }
return p;
}
}
// namespace manapi::stl {
// /*
// * Useful allocator alias
// */
// template<typename T>
// using basic_allocator = ::jemallocator::jemallocator<T, jemallocator::jepolicy::empty::policy>;
//
// template<typename T>
// using default_allocator = basic_allocator<T>;
//
// /*
// * Useful container aliases
// */
//
// template<typename T, class Alloc = default_allocator<T>>
// using forward_list = std::forward_list<T, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using deque = std::deque<T, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using list = std::list<T, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using vector = std::vector<T, Alloc>;
//
// template<typename Key, typename T, class Alloc = default_allocator<std::pair<const Key, T>>>
// using map = std::map<Key, T, std::less<Key>, Alloc>;
//
// template<typename Key, typename T, class Alloc = default_allocator<std::pair<const Key, T>>>
// using multimap = std::multimap<Key, T, std::less<Key>, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using multiset = std::multiset<T, std::less<T>, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using set = std::set<T, std::less<T>, Alloc>;
//
// template<typename Key, typename T, class Alloc = default_allocator<std::pair<const Key, T>>>
// using unordered_map = std::unordered_map<Key, T, std::hash<Key>, std::equal_to<Key>, Alloc>;
//
// template<typename Key, typename T, class Alloc = default_allocator<std::pair<const Key, T>>>
// using unordered_multimap = std::unordered_multimap<Key, T, std::hash<Key>, std::equal_to<Key>, Alloc>;
//
// template<typename Key, class Alloc = default_allocator<Key>>
// using unordered_multiset = std::unordered_multiset<Key, std::hash<Key>, std::equal_to<Key>, Alloc>;
//
// template<typename Key, class Alloc = default_allocator<Key>>
// using unordered_set = std::unordered_set<Key, std::hash<Key>, std::equal_to<Key>, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using stack = std::stack<T, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using queue = std::queue<T, Alloc>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using priority_queue = std::priority_queue<T, std::vector<T, Alloc>, std::less<typename std::vector<T, Alloc>::value_type>>;
//
// template<typename T, class Alloc = default_allocator<T>>
// using basic_string = std::basic_string<T, std::char_traits<T>, Alloc>;
//
// using string = basic_string<char>;
// using wstring = basic_string<wchar_t>;
// using u16string = basic_string<char16_t>;
// using u32string = basic_string<char32_t>;
// }