mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Add float/int literal for Approx
This commit is contained in:
		 Henry Schreiner
					Henry Schreiner
				
			
				
					committed by
					
						 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
			
				
	
			
			
			 Martin Hořeňovský
						Martin Hořeňovský
					
				
			
						parent
						
							d6c7392b24
						
					
				
				
					commit
					283e2e6d41
				
			| @@ -35,6 +35,13 @@ namespace Detail { | ||||
|         return Approx( 0 ); | ||||
|     } | ||||
|  | ||||
|     Approx Approx::operator-() const { | ||||
|         auto temp(*this); | ||||
|         temp.m_value = -temp.m_value; | ||||
|         return temp; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     std::string Approx::toString() const { | ||||
|         ReusableStringStream rss; | ||||
|         rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; | ||||
| @@ -49,6 +56,15 @@ namespace Detail { | ||||
|  | ||||
| } // end namespace Detail | ||||
|  | ||||
| namespace literals { | ||||
|     Detail::Approx operator "" _a(long double val) { | ||||
|         return Detail::Approx(val); | ||||
|     } | ||||
|     Detail::Approx operator "" _a(unsigned long long val) { | ||||
|         return Detail::Approx(val); | ||||
|     } | ||||
| } // end namespace literals | ||||
|  | ||||
| std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) { | ||||
|     return value.toString(); | ||||
| } | ||||
|   | ||||
| @@ -25,6 +25,8 @@ namespace Detail { | ||||
|  | ||||
|         static Approx custom(); | ||||
|  | ||||
|         Approx operator-() const; | ||||
|  | ||||
|         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 +123,12 @@ namespace Detail { | ||||
|         double m_scale; | ||||
|         double m_value; | ||||
|     }; | ||||
| } | ||||
| } // end namespace Detail | ||||
|      | ||||
| namespace literals { | ||||
|     Detail::Approx operator "" _a(long double val); | ||||
|     Detail::Approx operator "" _a(unsigned long long val); | ||||
| } // end namespace literals | ||||
|  | ||||
| template<> | ||||
| struct StringMaker<Catch::Detail::Approx> { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user