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_DIAGNOSTIC_NOINLINE ZEROERR_SFINAE_OP(Expression<R>, op) operator op(R&& rhs) { \
39 zeroerr::String text = \
40 detail::comparisonText(decomp, detail::makeDiagnosticValue(lhs), " " #op " ", \
41 detail::makeDiagnosticValue(rhs), res); \
42 return Expression<R>(static_cast<R&&>(rhs), res && (lhs op rhs), std::move(text)); \
44 template <typename R, \
45 typename std::enable_if<!std::is_rvalue_reference<R>::value, void>::type* = nullptr> \
46 ZEROERR_DIAGNOSTIC_NOINLINE ZEROERR_SFINAE_OP(Expression<const R&>, op) operator op( \
48 zeroerr::String text = \
49 detail::comparisonText(decomp, detail::makeDiagnosticValue(lhs), " " #op " ", \
50 detail::makeDiagnosticValue(rhs), res); \
51 return Expression<const R&>(rhs, res && (lhs op rhs), std::move(text)); \
55#define ZEROERR_EXPRESSION_ANDOR(op, op_name) \
56 ExprResult operator op(ExprResult rhs) { \
57 return ExprResult(res op rhs.res, \
58 detail::joinDiagnostic(decomp, " " #op " ", rhs.decomp)); \
62#define ZEROERR_FORBIT_EXPRESSION(rt, op) \
63 template <typename R> \
64 rt& operator op(const R&) { \
65 static_assert(deferred_false<R>::value, \
66 "Please Rewrite Expression As Binary Comparison!"); \
109#define ZEROERR_DIRECT_COMPARISON(op) \
111 ExprResult operator op(const R& rhs) const { \
112 return {lhs op rhs, printer(lhs, #op, rhs)}; \
120#undef ZEROERR_DIRECT_COMPARISON
125 return {lhs, printer};
136template <
typename T,
typename =
void>
141 : std::integral_constant<
142 bool, !(std::is_enum<typename std::decay<T>::type>::value &&
143 !std::is_convertible<typename std::decay<T>::type, int>::value)> {};
146typename std::enable_if<has_bool_conversion<T>::value,
bool>::type
getBool(T&& lhs) {
147 return static_cast<bool>(lhs);
151typename std::enable_if<!has_bool_conversion<T>::value,
bool>::type
getBool(T&&) {
173 operator L()
const {
return lhs; }
203#undef ZEROERR_EXPRESSION_COMPARISON
204#undef ZEROERR_EXPRESSION_ANDOR
205#undef ZEROERR_FORBIT_EXPRESSION
215 template <
typename L>
221 template <
typename L,
222 typename std::enable_if<!std::is_rvalue_reference<L>::value,
void>::type* =
nullptr>
235 virtual bool match(
const T&)
const = 0;
245 p = std::move(other.p);
249 p = std::move(other.p);
278 virtual bool match(
const T& t)
const override {
280 return lhs->match(t) &&
rhs->match(t);
282 return lhs->match(t) ||
rhs->match(t);
293 virtual bool match(
const T& t)
const override {
return !
matcher->match(t); }
317 virtual bool match(
const T& t)
const override {
319 for (
auto i =
start.begin(), j = t.begin(); i !=
start.end(); ++i, ++j) {
320 if (j == t.end() || *i != *j) {
330typename std::enable_if<std::is_constructible<zeroerr::String, T>::value,
331 IMatcherRef<zeroerr::String>>::type
IMatcherRef< T > lhs
定义 decomposition.h:274
IMatcherRef< T > rhs
定义 decomposition.h:275
virtual bool match(const T &t) const override
定义 decomposition.h:278
bool is_and
定义 decomposition.h:276
CombinedMatcher(IMatcherRef< T > &&lhs, IMatcherRef< T > &&rhs, bool is_and)
定义 decomposition.h:271
IMatcherRef(IMatcherRef &&other)
定义 decomposition.h:244
IMatcherRef operator||(IMatcherRef &&other)
定义 decomposition.h:302
IMatcherRef(const IMatcher< T > *ptr)
定义 decomposition.h:241
void operator=(IMatcherRef &&other)
定义 decomposition.h:248
IMatcherRef(const IMatcherRef &)=delete
const IMatcher< T > * p
定义 decomposition.h:264
IMatcherRef operator&&(IMatcherRef &&other)
定义 decomposition.h:297
IMatcherRef & operator=(const IMatcherRef &)=delete
const IMatcher< T > * operator->() const
定义 decomposition.h:261
IMatcherRef operator!()
定义 decomposition.h:307
~IMatcherRef()
定义 decomposition.h:253
virtual bool match(const T &) const =0
virtual ~IMatcher()=default
IMatcherRef< T > matcher
定义 decomposition.h:291
NotMatcher(IMatcherRef< T > &&matcher)
定义 decomposition.h:290
virtual bool match(const T &t) const override
定义 decomposition.h:293
#define ZEROERR_SUPPRESS_COMPARE
定义 config.h:318
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_POP
定义 config.h:283
#define ZEROERR_SUPPRESS_COMPARE_POP
定义 config.h:331
#define ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
定义 config.h:235
#define ZEROERR_FORBIT_EXPRESSION(rt, op)
定义 decomposition.h:62
#define ZEROERR_EXPRESSION_ANDOR(op, op_name)
定义 decomposition.h:55
#define ZEROERR_EXPRESSION_COMPARISON(op, op_name)
定义 decomposition.h:36
#define ZEROERR_DIRECT_COMPARISON(op)
定义 decomposition.h:109
zeroerr::String valueText(DiagnosticValue value)
定义 text.cpp:63
ComparisonLhs< L > makeComparisonLhs(const L &lhs, Printer &printer)
定义 decomposition.h:124
DiagnosticValue makeDiagnosticValue(T &value)
定义 print.h:364
std::enable_if< has_bool_conversion< T >::value, bool >::type getBool(T &&lhs)
定义 decomposition.h:146
std::enable_if< std::is_constructible< zeroerr::String, T >::value, IMatcherRef< zeroerr::String > >::type start_with(T &&s)
定义 decomposition.h:332
bool res
定义 decomposition.h:71
zeroerr::String decomp
定义 decomposition.h:72
ExprResult(bool res, zeroerr::String decomposition="")
定义 decomposition.h:74
Expression< L > operator<<(L &&operand)
定义 decomposition.h:216
bool res
定义 decomposition.h:159
zeroerr::String decomp
定义 decomposition.h:160
L lhs
定义 decomposition.h:158
Expression(L &&in)
定义 decomposition.h:162
Expression(L &&in, bool res, zeroerr::String &&decomp)
定义 decomposition.h:163
A functor class Printer for printing a value of any type.
定义 print.h:87
StartWithMatcher(const T &s)
定义 decomposition.h:314
virtual bool match(const T &t) const override
定义 decomposition.h:317
T start
定义 decomposition.h:315
static const bool value
定义 decomposition.h:33
Printer & printer
定义 decomposition.h:107
const L & lhs
定义 decomposition.h:106