11 #ifndef ZEROERR_DISABLE_COMPLEX_AND_OR
20 #define AND &&zeroerr::ExpressionDecomposer() <<
21 #define OR || zeroerr::ExpressionDecomposer() <<
28 #define ZEROERR_SFINAE_OP(ret, op) \
29 typename std::decay<decltype(std::declval<L>() op std::declval<R>(), std::declval<ret>())>::type
33 static const bool value =
false;
36 #define ZEROERR_EXPRESSION_COMPARISON(op, op_name) \
37 template <typename R> \
38 ZEROERR_SFINAE_OP(Expression<R>, op) \
39 operator op(R && rhs) { \
40 std::stringstream ss; \
42 print.isCompact = true; \
43 print.line_break = ""; \
44 if (decomp.empty()) { \
51 return Expression<R>(static_cast<R&&>(rhs), res && (lhs op rhs), ss.str()); \
53 template <typename R, \
54 typename std::enable_if<!std::is_rvalue_reference<R>::value, void>::type* = nullptr> \
55 ZEROERR_SFINAE_OP(Expression<const R&>, op) \
56 operator op(const R & rhs) { \
57 std::stringstream ss; \
59 print.isCompact = true; \
60 print.line_break = ""; \
61 if (decomp.empty()) { \
68 return Expression<const R&>(rhs, res && (lhs op rhs), ss.str()); \
71 #define ZEROERR_EXPRESSION_ANDOR(op, op_name) \
72 ExprResult operator op(ExprResult rhs) { \
73 std::stringstream ss; \
74 ss << decomp << " " #op " " << rhs.decomp; \
75 return ExprResult(res op rhs.res, ss.str()); \
79 #define ZEROERR_FORBIT_EXPRESSION(rt, op) \
80 template <typename R> \
81 rt& operator op(const R&) { \
82 static_assert(deferred_false<R>::value, \
83 "Please Rewrite Expression As Binary Comparison!"); \
118 template <
typename T>
119 typename std::enable_if<std::is_convertible<T, bool>::value,
bool>::type
getBool(T&& lhs) {
120 return static_cast<bool>(lhs);
123 template <
typename T>
124 typename std::enable_if<!std::is_convertible<T, bool>::value,
bool>::type
getBool(T&&) {
129 template <
typename L>
149 operator L()
const {
return lhs; }
179 #undef ZEROERR_EXPRESSION_COMPARISON
180 #undef ZEROERR_EXPRESSION_ANDOR
181 #undef ZEROERR_FORBIT_EXPRESSION
191 template <
typename L>
197 template <
typename L,
198 typename std::enable_if<!std::is_rvalue_reference<L>::value,
void>::type* =
nullptr>
205 template <
typename T>
211 virtual bool match(
const T&)
const = 0;
214 template <
typename T>
221 p = std::move(other.p);
225 p = std::move(other.p);
244 template <
typename T>
248 : lhs(std::move(lhs)), rhs(std::move(rhs)), is_and(is_and) {}
254 virtual bool match(
const T& t)
const override {
256 return lhs->match(t) && rhs->match(t);
258 return lhs->match(t) || rhs->match(t);
263 template <
typename T>
269 virtual bool match(
const T& t)
const override {
return !matcher->match(t); }
272 template <
typename T>
277 template <
typename T>
282 template <
typename T>
288 template <
typename T>
293 virtual bool match(
const T& t)
const override {
295 for (
auto i = start.begin(), j = t.begin(); i != start.end(); ++i, ++j) {
296 if (j == t.end() || *i != *j) {
305 template <
typename T>
306 typename std::enable_if<std::is_constructible<std::string, T>::value,
307 IMatcherRef<std::string>>::type
Definition: decomposition.h:245
IMatcherRef< T > lhs
Definition: decomposition.h:250
IMatcherRef< T > rhs
Definition: decomposition.h:251
virtual bool match(const T &t) const override
Definition: decomposition.h:254
bool is_and
Definition: decomposition.h:252
CombinedMatcher(IMatcherRef< T > &&lhs, IMatcherRef< T > &&rhs, bool is_and)
Definition: decomposition.h:247
Definition: decomposition.h:215
IMatcherRef(IMatcherRef &&other)
Definition: decomposition.h:220
IMatcherRef operator||(IMatcherRef &&other)
Definition: decomposition.h:278
IMatcherRef(const IMatcher< T > *ptr)
Definition: decomposition.h:217
void operator=(IMatcherRef &&other)
Definition: decomposition.h:224
IMatcherRef(const IMatcherRef &)=delete
IMatcherRef operator&&(IMatcherRef &&other)
Definition: decomposition.h:273
const IMatcher< T > * operator->() const
Definition: decomposition.h:237
IMatcherRef operator!()
Definition: decomposition.h:283
IMatcherRef & operator=(const IMatcherRef &)=delete
~IMatcherRef()
Definition: decomposition.h:229
Definition: decomposition.h:206
virtual bool match(const T &) const =0
virtual ~IMatcher()=default
Definition: decomposition.h:264
IMatcherRef< T > matcher
Definition: decomposition.h:267
NotMatcher(IMatcherRef< T > &&matcher)
Definition: decomposition.h:266
virtual bool match(const T &t) const override
Definition: decomposition.h:269
#define ZEROERR_SUPPRESS_COMPARE
Definition: config.h:299
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
Definition: config.h:265
#define ZEROERR_SUPPRESS_COMPARE_POP
Definition: config.h:312
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
Definition: config.h:218
#define ZEROERR_FORBIT_EXPRESSION(rt, op)
Definition: decomposition.h:79
#define ZEROERR_EXPRESSION_ANDOR(op, op_name)
Definition: decomposition.h:71
#define ZEROERR_EXPRESSION_COMPARISON(op, op_name)
Definition: decomposition.h:36
std::ostream & operator<<(std::ostream &os, const XmlEncode &xmlEncode)
Definition: unittest.cpp:570
std::enable_if<!std::is_convertible< T, bool >::value, bool >::type getBool(T &&)
Definition: decomposition.h:124
std::enable_if< std::is_convertible< T, bool >::value, bool >::type getBool(T &&lhs)
Definition: decomposition.h:119
Definition: benchmark.cpp:17
std::enable_if< std::is_constructible< std::string, T >::value, IMatcherRef< std::string > >::type start_with(T &&s)
Definition: decomposition.h:308
Definition: decomposition.h:87
std::string decomp
Definition: decomposition.h:89
bool res
Definition: decomposition.h:88
ExprResult(bool res, std::string decomposition="")
Definition: decomposition.h:91
Definition: decomposition.h:183
Definition: decomposition.h:130
Expression(L &&in, bool res, std::string &&decomp)
Definition: decomposition.h:136
std::string decomp
Definition: decomposition.h:133
L lhs
Definition: decomposition.h:131
Expression(L &&in)
Definition: decomposition.h:135
A functor class Printer for printing a value of any type.
Definition: print.h:80
std::string str() const
Definition: print.h:270
bool isCompact
Definition: print.h:122
const char * line_break
Definition: print.h:125
Definition: decomposition.h:289
StartWithMatcher(const T &s)
Definition: decomposition.h:290
virtual bool match(const T &t) const override
Definition: decomposition.h:293
T start
Definition: decomposition.h:291
Definition: decomposition.h:32
static const bool value
Definition: decomposition.h:33