-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibmisc.h
38 lines (33 loc) · 878 Bytes
/
libmisc.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
#pragma once
#ifdef __GXX_EXPERIMENTAL_CXX0X__
inline int min(int val)
{
return val;
}
template<typename... Args> inline int min(int arg1, const Args&... args)//if this is functional programming, I don't want to know more about it.
{
int i=min(args...);
if (arg1<i) return arg1;
return i;
}
inline int posmin(int val)
{
return val;
}
template<typename... Args> inline int posmin(int arg1, const Args&... args)
{
int i=posmin(args...);
if (arg1>=0 && arg1<i) return arg1;
return i;
}
#endif
template<int N> struct forceconst { enum { value = N }; };
#define forceconst(n) (forceconst<n>::value)
//from nall, license: ISC
//round up to next highest single bit:
//round(15) == 16, round(16) == 16, round(17) == 32
inline unsigned bitround(unsigned x) {
if((x & (x - 1)) == 0) return x;
while(x & (x - 1)) x &= x - 1;
return x << 1;
}