Make Approx::operator() const

Closes #2273
This commit is contained in:
Martin Hořeňovský 2021-08-26 20:56:18 +02:00
parent 54edab53bf
commit ff0a5227ca
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 8 additions and 1 deletions

View File

@ -30,7 +30,7 @@ namespace Catch {
Approx operator-() const; Approx operator-() const;
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>> template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
Approx operator()( T const& value ) { Approx operator()( T const& value ) const {
Approx approx( static_cast<double>(value) ); Approx approx( static_cast<double>(value) );
approx.m_epsilon = m_epsilon; approx.m_epsilon = m_epsilon;
approx.m_margin = m_margin; approx.m_margin = m_margin;

View File

@ -209,3 +209,10 @@ TEST_CASE( "Comparison with explicitly convertible types", "[Approx]" )
REQUIRE(Approx(11.0) >= td); REQUIRE(Approx(11.0) >= td);
} }
TEST_CASE("Approx::operator() is const correct", "[Approx][.approvals]") {
const Approx ap = Approx(0.0).margin(0.01);
// As long as this compiles, the test should be considered passing
REQUIRE(1.0 == ap(1.0));
}