47namespace kassert::internal {
62 [[nodiscard]]
virtual bool result()
const = 0;
81template <
typename LhsT,
typename RhsT>
98 [[nodiscard]]
bool result() const final {
112 out <<
" " << _op <<
" ";
119#define KASSERT_ASSERT_OP(op) \
120 template <typename RhsPrimeT> \
121 friend BinaryExpression<BinaryExpression<LhsT, RhsT>, RhsPrimeT> operator op( \
122 BinaryExpression<LhsT, RhsT>&& lhs, \
123 RhsPrimeT const& rhs_prime \
125 using namespace std::string_view_literals; \
126 return BinaryExpression<BinaryExpression<LhsT, RhsT>, RhsPrimeT>( \
127 lhs.result() op rhs_prime, \
137 KASSERT_ASSERT_OP(==)
138 KASSERT_ASSERT_OP(!=)
140#undef KASSERT_ASSERT_OP
150 std::string_view _op;
157template <
typename LhsT>
166 [[nodiscard]]
bool result() const final {
167 return static_cast<bool>(_lhs);
184template <
typename LhsT>
195 static_assert(std::is_convertible_v<LhsT, bool>,
"expression must be convertible to bool");
208#define KASSERT_ASSERT_OP(op) \
209 template <typename RhsT> \
210 friend BinaryExpression<LhsT, RhsT> operator op(LhsExpression&& lhs, RhsT const& rhs) { \
211 using namespace std::string_view_literals; \
212 return {lhs._lhs op rhs, lhs._lhs, #op##sv, rhs}; \
215 KASSERT_ASSERT_OP(==)
216 KASSERT_ASSERT_OP(!=)
218 KASSERT_ASSERT_OP(<=)
220 KASSERT_ASSERT_OP(>=)
225#undef KASSERT_ASSERT_OP
240 template <
typename LhsT>
258template <
typename ExprT>
260 if constexpr (std::is_base_of_v<Expression, std::remove_reference_t<std::remove_const_t<ExprT>>>) {
261 return std::forward<ExprT>(expr);
263 return expr.make_unary();
Simple wrapper for output streams that is used to stringify values in assertions and exceptions.
Definition: logger.hpp:47
A decomposed binary expression.
Definition: expression_decomposition.hpp:82
void stringify(OStreamLogger &out) const final
Writes this expression with stringified operands to the given assertion logger.
Definition: expression_decomposition.hpp:110
BinaryExpression(bool const result, LhsT const &lhs, std::string_view const op, RhsT const &rhs)
Constructs a decomposed binary expression.
Definition: expression_decomposition.hpp:89
bool result() const final
The boolean result of the expression. This is used when retrieving the expression result after decomp...
Definition: expression_decomposition.hpp:98
Interface for decomposed unary and binary expressions.
Definition: expression_decomposition.hpp:55
virtual void stringify(OStreamLogger &out) const =0
Write this expression with stringified operands to the given assertion logger.
friend OStreamLogger & operator<<(OStreamLogger &out, Expression const &expr)
Writes an expression with stringified operands to the given assertion logger.
Definition: expression_decomposition.hpp:72
virtual ~Expression()=default
Virtual destructor since we use virtual functions.
virtual bool result() const =0
Evaluate the assertion wrapped in this Expr.
The left hand size of a decomposed expression. This can either be turned into a BinaryExpr if an oper...
Definition: expression_decomposition.hpp:185
LhsExpression(LhsT const &lhs)
Constructs this left hand size of a decomposed expression.
Definition: expression_decomposition.hpp:189
UnaryExpression< LhsT > make_unary()
Turns this expression into an UnaryExpr. This might only be called if the wrapped expression is impli...
Definition: expression_decomposition.hpp:194
Decomposed unary expression.
Definition: expression_decomposition.hpp:158
UnaryExpression(LhsT const &lhs)
Constructs this unary expression from an expression.
Definition: expression_decomposition.hpp:162
bool result() const final
Evaluates this expression.
Definition: expression_decomposition.hpp:166
void stringify(OStreamLogger &out) const final
Writes this expression with stringified operands to the given assertion logger.
Definition: expression_decomposition.hpp:172
bool finalize_expr(bool const result)
If an expression cannot be decomposed (due to && or ||, to preserve short-circuit evaluation),...
Definition: expression_decomposition.hpp:250
void stringify_value(Logger< StreamT > &out, ValueT const &value)
Stringify a value using the given assertion logger. If the value cannot be streamed into the logger,...
Definition: logger.hpp:103
Logger utility class to build error messages for failed assertins.
Type trait that is always false, to implement static_asserts that always fail, thus preventing a temp...
Definition: expression_decomposition.hpp:52
Decomposes an expression (see group description).
Definition: expression_decomposition.hpp:235
friend LhsExpression< LhsT > operator<=(Decomposer &&, LhsT const &lhs)
Decomposes an expression (see group description).
Definition: expression_decomposition.hpp:241