Skip to content

Commit

Permalink
Make Approx::operator() const
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar committed Aug 26, 2021
1 parent 0a8516a commit 7bea1e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/catch2/catch_approx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/SelfTest/UsageTests/Approx.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 7bea1e2

Please sign in to comment.