/
util.h
48 lines (41 loc) · 1.1 KB
/
util.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
45
46
47
48
#pragma once
#include <algorithm>
#include <functional>
void* Decompress(const void* source, int* size);
void Decompress(void* destination, const void* source);
void PrintStatus(const char* format, ...);
template <typename It>
static inline void delete_each(It begin, It end)
{
for (It it = begin; it != end; ++it)
{
delete *it;
*it = NULL;
}
}
template <typename Container>
void delete_and_clear(Container & c)
{
delete_each(c.begin(), c.end());
c.clear();
}
template <typename Container, typename Predicate>
static inline void delete_and_erase_if(Container & c, Predicate const & p)
{
typename Container::iterator keep =
std::partition(c.begin(), c.end(), p);
delete_each(c.begin(), keep);
c.erase(c.begin(), keep);
}
template <typename Container, typename Unary>
static inline void for_each(Container & c, Unary const & u)
{
std::for_each(c.begin(), c.end(), u);
}
template <typename Result, typename X, typename Arg>
static inline
typename std::binder2nd< typename std::mem_fun1_t<Result, X, Arg> >
mem_fun_with(Result (X::*f)(Arg), Arg const & arg)
{
return std::bind2nd(std::mem_fun(f), arg);
}