-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutility.hpp
More file actions
47 lines (45 loc) · 1.26 KB
/
Copy pathutility.hpp
File metadata and controls
47 lines (45 loc) · 1.26 KB
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
#ifndef HMLIB_UTILITY_INC
#define HMLIB_UTILITY_INC 100
#
#include<utility>
namespace hmLib{
namespace utility{
extern void* enabler;
}
}
#define hmLib_static_restrict(condition) typename std::enable_if<condition>::type*& = hmLib::utility::enabler
#define hmLib_unused(expr) do{(void)(expr);}while(0)
namespace hmLib{
template<typename T, typename U>
T exchange(T& obj, U&& new_val) {
T old_val = std::move(obj);
obj = std::forward<U>(new_val);
return old_val;
}
//static size wrapper
namespace detail{
template<typename container>
struct static_size_impl{
static constexpr std::size_t static_size(){return container::static_size();}
};
template<typename T, std::size_t N>
struct static_size_impl<std::array<T, N>>{
static constexpr std::size_t static_size(){return N;}
};
template<typename T, std::size_t N>
struct static_size_impl<T[N]>{
static constexpr std::size_t static_size(){return N;}
};
}
//static size generalized for std::array and raw array types.
template<typename container>
constexpr std::size_t static_size(){
return detail::static_size_impl<container>::static_size();
}
template<typename T>
inline bool are_equal(T v1, T v2, double tolerance = 1e-8) {
return v1+tolerance >= v2 && v2+tolerance >= v1;
}
}
#
#endif