mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-26 06:25:40 +02:00
Add float/int literal for Approx
This commit is contained in:

committed by
Henry Fredrick Schreiner

parent
df0b0e64e1
commit
77230e69ad
@@ -25,6 +25,14 @@ namespace Detail {
|
||||
|
||||
static Approx custom();
|
||||
|
||||
Approx operator-() const {
|
||||
Approx approx( -static_cast<double>(m_value) );
|
||||
approx.epsilon( m_epsilon );
|
||||
approx.margin( m_margin );
|
||||
approx.scale( m_scale );
|
||||
return approx;
|
||||
}
|
||||
|
||||
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||
Approx operator()( T const& value ) {
|
||||
Approx approx( static_cast<double>(value) );
|
||||
@@ -121,7 +129,17 @@ namespace Detail {
|
||||
double m_scale;
|
||||
double m_value;
|
||||
};
|
||||
}
|
||||
} // end namespace Detail
|
||||
|
||||
namespace literals {
|
||||
inline Detail::Approx operator "" _a(long double val) {
|
||||
return Detail::Approx(val);
|
||||
}
|
||||
|
||||
inline Detail::Approx operator "" _a(unsigned long long val) {
|
||||
return Detail::Approx(val);
|
||||
}
|
||||
} // end namespace literals
|
||||
|
||||
template<>
|
||||
struct StringMaker<Catch::Detail::Approx> {
|
||||
|
Reference in New Issue
Block a user