-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlispUtils.h
45 lines (36 loc) · 901 Bytes
/
lispUtils.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
#include <boost/lexical_cast.hpp>
// need this to use visitor on vector
template<typename Visitor, typename Element>
typename Visitor::result_type
apply_visitor(const Visitor& visitor, const Element& operand) {
return visitor(operand);
}
class print_visitor
: public boost::static_visitor<std::string>
{
public:
std::string operator()( const std::string& str ) const
{
return "'"+str+"'";
}
template<typename T>
std::string operator()( const T& val ) const
{
return boost::lexical_cast<std::string>(val);
}
std::string operator()( const Expression& val ) const
{
return boost::apply_visitor(*this,val);
}
template<typename T>
std::string operator()( const std::vector<T>& list ) const
{
std::string out;
out += "(";
for (auto elem : list) {
out += " "+::apply_visitor(*this,elem);
}
out += ")";
return out;
}
};