~
[scx.git] / include / Alias.hpp
blob5e67980a46b90682667cd57cc9664ebb89618d6e
1 #ifndef SCX_ALIAS_HPP
2 #define SCX_ALIAS_HPP
4 // align
5 #define SCX_ALIGN(d, a) ( ( (int)(( (d)-1 )/(a)) + 1 ) * (a) )
6 #define SCX_QALIGN(d, a) ( ( (d) + ((a) - 1) ) & ~((a) - 1) )
8 // bit
9 #define SCX_BIT(n) ( 1 << (n) )
11 // len
12 #define SCX_ARRAY_LEN(a) (sizeof(a)/sizeof(a[0]))
14 // for
15 #define SCX_FOR(index, begin, _end) \
16 for (size_t index = begin, end = _end; \
17 index < end; \
18 ++index)
20 // for stl vector etc.
21 #define foreach_linear(index, container) \
22 for (size_t index = 0; \
23 index < (container).size(); \
24 ++index)
26 #define forrange_linear(index, begin, end) \
27 for (size_t index = begin; \
28 index < end; \
29 ++index)
31 // for stl map etc.
32 #define foreach_iterator(iter_t, iter, container) \
33 for (iter_t iter = container.begin(); \
34 iter < container.end(); \
35 ++iter)
37 #define forrange_iterator(iter_t, iter, begin, end) \
38 for (iter_t iter = begin; \
39 iter != end; \
40 ++iter)
41 #endif