-
Notifications
You must be signed in to change notification settings - Fork 14
/
Variant.h
31 lines (26 loc) · 1.26 KB
/
Variant.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
/**
* @file Variant.h Provides a number of shorthands for declaring boost::variant
* visitor types.
*/
#ifndef _NOTENGLISH_BOOST_VARIANT_H_INCLUDE_GUARD
#define _NOTENGLISH_BOOST_VARIANT_H_INCLUDE_GUARD
#include <boost/variant.hpp>
#define OPERATOR_VISITOR(Name, Operator, Type, Funcs) \
struct Name : public boost::static_visitor<Type> { \
typedef Type VarType; \
template<class T, class U> \
VarType operator()(const T& lhs, const U& rhs) const \
{ \
throw std::runtime_error( \
"invalid usage of operator" \
); \
return VarType(); \
} \
Funcs \
};
#define VISITOR_PART(Type, Operator) \
VarType operator()(const Type& lhs, const Type& rhs) const \
{ \
return VarType(lhs Operator rhs); \
}
#endif // _NOTENGLISH_BOOST_VARIANT_H_INCLUDE_GUARD