Split out non-templated Approx methods into cpp file

This commit is contained in:
Martin Hořeňovský 2017-07-19 10:01:06 +02:00
parent 0a614ee5ba
commit edbe122761
3 changed files with 44 additions and 20 deletions

View File

@ -193,6 +193,7 @@ set(INTERNAL_HEADERS
${HEADER_DIR}/internal/catch_xmlwriter.hpp
)
set(IMPL_SOURCES
${HEADER_DIR}/internal/catch_approx.cpp
${HEADER_DIR}/internal/catch_assertionresult.cpp
${HEADER_DIR}/internal/catch_commandline.cpp
${HEADER_DIR}/internal/catch_common.cpp

View File

@ -0,0 +1,39 @@
/*
* Created by Martin on 19/07/2017.
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include "catch_approx.hpp"
#include <limits>
namespace Catch {
namespace Detail {
Approx::Approx ( double value )
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_margin( 0.0 ),
m_scale( 1.0 ),
m_value( value )
{}
Approx Approx::custom() {
return Approx( 0 );
}
std::string Approx::toString() const {
std::ostringstream oss;
oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )";
return oss.str();
}
} // end namespace Detail
std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
return value.toString();
}
} // end namespace Catch

View File

@ -20,18 +20,9 @@ namespace Detail {
class Approx {
public:
explicit Approx ( double value )
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_margin( 0.0 ),
m_scale( 1.0 ),
m_value( value )
{}
explicit Approx ( double value );
Approx( Approx const& other ) = default;
static Approx custom() {
return Approx( 0 );
}
static Approx custom();
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
Approx operator()( T value ) {
@ -111,12 +102,7 @@ namespace Detail {
return *this;
}
std::string toString() const {
std::ostringstream oss;
oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )";
return oss.str();
}
std::string toString() const;
private:
double m_epsilon;
@ -128,9 +114,7 @@ namespace Detail {
template<>
struct StringMaker<Catch::Detail::Approx> {
static std::string convert(Catch::Detail::Approx const& value) {
return value.toString();
}
static std::string convert(Catch::Detail::Approx const& value);
};
} // end namespace Catch