-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
44 lines (36 loc) · 1.22 KB
/
utils.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
#ifndef CHESSUCIENGINE_UTILS_H
#define CHESSUCIENGINE_UTILS_H
#include <iostream>
#define EnableAssertions false
#define HandleError(block) if (!(block)) {\
std::cerr << "Execution fail at " << __FILE__ << ":" << __LINE__ << " (in " << __func__ << ")" << std::endl;\
std::cerr << "Error code is " << GetLastError() << std::endl;\
exit(GetLastError());\
}
#if EnableAssertions
#define Assert(block) if (!(block)) {\
std::cerr << "Assertion failed at " << __FILE__ << ":" << __LINE__ << " (in " << __func__ << ")" << std::endl; \
_CrtDbgBreak(); \
exit(1);\
}
#else
#define Assert(block) block;
#endif
inline void hash_combine(std::size_t& seed) { }
template <typename T, typename... Rest>
inline void hash_combine(std::size_t& seed, const T& v, Rest... rest) {
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
hash_combine(seed, rest...);
}
#define MAKE_HASHABLE(type, ...) \
namespace std {\
template<> struct hash<type> {\
std::size_t operator()(const type &t) const {\
std::size_t ret = 0;\
hash_combine(ret, __VA_ARGS__);\
return ret;\
}\
};\
}
#endif //CHESSUCIENGINE_UTILS_H