8#ifndef TWOBLUECUBES_CATCH_DECOMPOSER_H_INCLUDED
9#define TWOBLUECUBES_CATCH_DECOMPOSER_H_INCLUDED
19#pragma warning(disable:4389)
20#pragma warning(disable:4018)
21#pragma warning(disable:4312)
22#pragma warning(disable:4180)
23#pragma warning(disable:4800)
28 struct ITransientExpression {
49 template<
typename LhsT,
typename RhsT>
55 void streamReconstructedExpression( std::ostream &
os )
const override {
71 "chained comparisons are not supported inside assertions, "
72 "wrap the expression inside parentheses, or decompose it");
78 "chained comparisons are not supported inside assertions, "
79 "wrap the expression inside parentheses, or decompose it");
85 "chained comparisons are not supported inside assertions, "
86 "wrap the expression inside parentheses, or decompose it");
92 "chained comparisons are not supported inside assertions, "
93 "wrap the expression inside parentheses, or decompose it");
99 "chained comparisons are not supported inside assertions, "
100 "wrap the expression inside parentheses, or decompose it");
106 "chained comparisons are not supported inside assertions, "
107 "wrap the expression inside parentheses, or decompose it");
113 "chained comparisons are not supported inside assertions, "
114 "wrap the expression inside parentheses, or decompose it");
120 "chained comparisons are not supported inside assertions, "
121 "wrap the expression inside parentheses, or decompose it");
125 template<
typename LhsT>
126 class UnaryExpr :
public ITransientExpression {
129 void streamReconstructedExpression( std::ostream &
os )
const override {
142 template<
typename LhsT,
typename RhsT>
143 auto compareEqual( LhsT
const& lhs, RhsT
const& rhs ) ->
bool {
return static_cast<bool>(lhs == rhs); }
145 auto compareEqual(
T*
const& lhs,
int rhs ) ->
bool {
return lhs ==
reinterpret_cast<void const*
>( rhs ); }
147 auto compareEqual(
T*
const& lhs,
long rhs ) ->
bool {
return lhs ==
reinterpret_cast<void const*
>( rhs ); }
149 auto compareEqual(
int lhs,
T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) == rhs; }
151 auto compareEqual(
long lhs,
T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) == rhs; }
153 template<
typename LhsT,
typename RhsT>
154 auto compareNotEqual( LhsT
const& lhs, RhsT&& rhs ) ->
bool {
return static_cast<bool>(lhs != rhs); }
156 auto compareNotEqual(
T*
const& lhs,
int rhs ) ->
bool {
return lhs !=
reinterpret_cast<void const*
>( rhs ); }
158 auto compareNotEqual(
T*
const& lhs,
long rhs ) ->
bool {
return lhs !=
reinterpret_cast<void const*
>( rhs ); }
160 auto compareNotEqual(
int lhs,
T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) != rhs; }
162 auto compareNotEqual(
long lhs,
T*
const& rhs ) ->
bool {
return reinterpret_cast<void const*
>( lhs ) != rhs; }
165 template<
typename LhsT>
169 explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
171 template<
typename RhsT>
173 return {
compareEqual( m_lhs, rhs ), m_lhs,
"==", rhs };
176 return { m_lhs == rhs, m_lhs,
"==", rhs };
179 template<
typename RhsT>
184 return { m_lhs != rhs, m_lhs,
"!=", rhs };
187 template<
typename RhsT>
189 return {
static_cast<bool>(m_lhs > rhs), m_lhs,
">", rhs };
191 template<
typename RhsT>
193 return {
static_cast<bool>(m_lhs < rhs), m_lhs,
"<", rhs };
195 template<
typename RhsT>
197 return {
static_cast<bool>(m_lhs >= rhs), m_lhs,
">=", rhs };
199 template<
typename RhsT>
201 return {
static_cast<bool>(m_lhs <= rhs), m_lhs,
"<=", rhs };
204 template<
typename RhsT>
207 "operator&& is not supported inside assertions, "
208 "wrap the expression inside parentheses, or decompose it");
211 template<
typename RhsT>
214 "operator|| is not supported inside assertions, "
215 "wrap the expression inside parentheses, or decompose it");
auto operator==(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator||(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator<=(T) const -> BinaryExpr< LhsT, RhsT const & > const
BinaryExpr(bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs)
auto operator>=(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator<(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator>(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator!=(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator&&(T) const -> BinaryExpr< LhsT, RhsT const & > const
auto operator!=(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator>=(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator>(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator<=(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto makeUnaryExpr() const -> UnaryExpr< LhsT >
auto operator&&(RhsT const &) -> BinaryExpr< LhsT, RhsT const & > const
auto operator||(RhsT const &) -> BinaryExpr< LhsT, RhsT const & > const
auto operator==(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
auto operator<(RhsT const &rhs) -> BinaryExpr< LhsT, RhsT const & > const
std::string stringify(const T &e)
void formatReconstructedExpression(std::ostream &os, std::string const &lhs, StringRef op, std::string const &rhs)
void handleExpression(ITransientExpression const &expr)
auto compareNotEqual(LhsT const &lhs, RhsT &&rhs) -> bool
auto compareEqual(LhsT const &lhs, RhsT const &rhs) -> bool
#define T(meth, val, expected)
auto operator<=(T const &lhs) -> ExprLhs< T const & >
virtual ~ITransientExpression()
auto getResult() const -> bool
auto isBinaryExpression() const -> bool
bool m_isBinaryExpression
virtual void streamReconstructedExpression(std::ostream &os) const =0
ITransientExpression(bool isBinaryExpression, bool result)