-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.hpp
85 lines (67 loc) · 1.36 KB
/
common.hpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef COMMON_HPP
#define COMMON_HPP
#include <iostream>
#include <tuple>
using std::cout;
using std::endl;
using std::get;
using std::tuple;
using std::ostream;
namespace AI
{
template<typename T, int I>
struct TuplePrint
{
void operator()(const T& t) const
{
TuplePrint<T,I-1>()(t);
cout <<"," << get<I>(t);
}
};
template<typename T>
struct TuplePrint<T,0>
{
void operator()(const T& t) const
{
cout << get<0>(t);
}
};
template<typename... Args>
ostream& operator<< (ostream& stream, const tuple<Args...>& data)
{
stream << "<";
TuplePrint<decltype(data), sizeof...(Args)-1>()(data);
stream << ">";
return stream;
}
template<typename R, typename Functor>
void mapToRoot(const R &node, Functor f)
{
if ( !node )
return;
f( node );
mapToRoot( node->parent(), f );
}
template <typename R>
void showRoute(const R & node )
{
using std::cout;
using std::endl;
cout << "Route to root: "<< node->getState();
mapToRoot(
node->parent(),
[](const R &n) { cout << " -> " << n->getState(); }
);
cout << endl;
}
namespace Private
{
template <typename T>
struct NodePtrCompare : std::less<T>
{
bool operator()(const T &lhs, const T &rhs) const
{ return lhs->getState() < rhs->getState(); }
};
} // endnamespace Private
} // endnamespace AI
#endif