diff options
| author | Martin Hořeňovský | 2021-08-26 20:56:18 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-08-26 21:27:43 +0200 |
| commit | ff0a5227caf84d466e3c9c8d6b58469d651e5268 (patch) | |
| tree | fae017eebef8b671741a0c4b7490a70c8aee2d04 | |
| parent | 54edab53bf38260a60e42e6faf73ce15b7224fe0 (diff) | |
| download | catch3-ff0a5227caf84d466e3c9c8d6b58469d651e5268.tar.gz | |
Make Approx::operator() const
Closes #2273
| -rw-r--r-- | src/catch2/catch_approx.hpp | 2 | ||||
| -rw-r--r-- | tests/SelfTest/UsageTests/Approx.tests.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/catch2/catch_approx.hpp b/src/catch2/catch_approx.hpp index 8f0e6327..7c3a17c0 100644 --- a/src/catch2/catch_approx.hpp +++ b/src/catch2/catch_approx.hpp @@ -30,7 +30,7 @@ namespace Catch { Approx operator-() const; 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.m_epsilon = m_epsilon; approx.m_margin = m_margin; diff --git a/tests/SelfTest/UsageTests/Approx.tests.cpp b/tests/SelfTest/UsageTests/Approx.tests.cpp index 96f9706d..1ae5fe04 100644 --- a/tests/SelfTest/UsageTests/Approx.tests.cpp +++ b/tests/SelfTest/UsageTests/Approx.tests.cpp @@ -209,3 +209,10 @@ TEST_CASE( "Comparison with explicitly convertible types", "[Approx]" ) 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)); +} |