-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
42 lines (33 loc) · 878 Bytes
/
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
#ifndef UTILS_H
#define UTILS_H
#include <type_traits>
template<typename EnumType>
constexpr auto enumToInt(EnumType e)
{
return static_cast<std::underlying_type_t<EnumType>>(e);
}
template<typename EnumType>
constexpr bool enumBetween(EnumType left, EnumType elm, EnumType right)
{
return enumToInt(elm) >= enumToInt(left) && enumToInt(elm) <= enumToInt(right);
}
template<typename... Fs>
struct overload : Fs...
{
using Fs::operator()...;
explicit overload(Fs&&... fs) : Fs(std::forward<Fs>(fs))... {}
};
template<typename... Fs>
overload(Fs...) -> overload<Fs...>;
inline size_t alignUp(size_t v, size_t a) {
// TODO performance can be improved
while (v % a != 0)
++v;
return v;
}
template<typename T, typename... Ts>
constexpr bool equalsAny(T const& e, Ts const&... cases)
{
return ((e == cases) || ...);
}
#endif //UTILS_H