From 04dff97fdeca79c3fced1240d893d2da3a27a6d9 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sun, 12 Jul 2020 13:38:54 +0200 Subject: [PATCH] Use explicit streaming ops instead of Boost.LexicalCast --- doc/example/patterns_quick_constraint.cpp | 6 ++++-- test/detail/test_type_name.cpp | 8 +++++--- test/mock_error.hpp | 13 ++++++------- test/test_log.cpp | 13 +++++++++---- test/test_mock.cpp | 1 - 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/doc/example/patterns_quick_constraint.cpp b/doc/example/patterns_quick_constraint.cpp index f1ae03b..5163020 100644 --- a/doc/example/patterns_quick_constraint.cpp +++ b/doc/example/patterns_quick_constraint.cpp @@ -35,13 +35,15 @@ namespace //] //[ quick_constraint_solution -#include +#include namespace // in the same namespace as 'my_class' { bool operator==( const my_class& actual, const std::string& expected ) // the first part of the trick is to compare to a string { - return boost::lexical_cast< std::string >( actual ) == expected; + std::ostringstream s; + s << actual; + return s.str() == expected; } } // mock diff --git a/test/detail/test_type_name.cpp b/test/detail/test_type_name.cpp index cdaf736..3040965 100644 --- a/test/detail/test_type_name.cpp +++ b/test/detail/test_type_name.cpp @@ -8,14 +8,16 @@ #include #include -#include +#include namespace { template< typename T > std::string to_string( const T& t) { - return boost::lexical_cast< std::string >( mock::detail::make_type_name(t) ); + std::ostringstream s; + s << mock::detail::make_type_name(t); // Typename can be streamed + return s.str(); } } @@ -111,7 +113,7 @@ BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted ) { struct my_local_type {}; - BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( mock::detail::make_type_name() ) ); + BOOST_CHECK_EQUAL( "my_local_type", to_string( my_local_type() ) ); } namespace diff --git a/test/mock_error.hpp b/test/mock_error.hpp index bd3fbe9..5821f52 100644 --- a/test/mock_error.hpp +++ b/test/mock_error.hpp @@ -11,9 +11,9 @@ #define MOCK_ERROR_POLICY mock_error #include -#include #include #include +#include struct mock_error_data_t : mock::detail::singleton< mock_error_data_t > { @@ -68,18 +68,17 @@ struct mock_error {} template< typename Context > - static void call( const Context& /*context*/, - const char* /*file*/, int /*line*/ ) + static void call( const Context& /*context*/, const char* /*file*/, int /*line*/ ) { mock_error_data.call(); } template< typename Context > - static void fail( const std::string& message, const Context& context, - const char* file = "", int line = 0 ) + static void fail( const std::string& message, const Context& context, const char* file = "", int line = 0 ) { - mock_error_data.fail( message, - boost::lexical_cast< std::string >( context ), file, line ); + std::ostringstream s; + s << context; // Context can be streamed + mock_error_data.fail( message, s.str(), file, line ); } }; diff --git a/test/test_log.cpp b/test/test_log.cpp index f4d7c81..f26d649 100644 --- a/test/test_log.cpp +++ b/test/test_log.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #ifdef BOOST_MSVC #pragma warning( push, 0 ) @@ -55,13 +54,19 @@ BOOST_AUTO_TEST_CASE( pointer_yields_its_value_when_serialized ) { { int i = 0; + std::ostringstream s; + s << &i; + const std::string pointerValue = s.str(); BOOST_CHECK_NE( "?", to_string( &i ) ); - BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( &i ), to_string( &i ) ); + BOOST_CHECK_EQUAL( pointerValue, to_string( &i ) ); } { const int i = 0; + std::ostringstream s; + s << &i; + const std::string pointerValue = s.str(); BOOST_CHECK_NE( "?", to_string( &i ) ); - BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( &i ), to_string( &i ) ); + BOOST_CHECK_EQUAL( pointerValue, to_string( &i ) ); } } @@ -630,7 +635,7 @@ BOOST_AUTO_TEST_CASE( mock_detail_template_template_streamable_yields_its_value_ BOOST_AUTO_TEST_CASE( unsigned_char_is_serialized_as_int ) { - BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( static_cast< int >( 'a' ) ), to_string< unsigned char >( 'a' ) ); + BOOST_CHECK_EQUAL( std::to_string( static_cast< int >( 'a' ) ), to_string< unsigned char >( 'a' ) ); } namespace diff --git a/test/test_mock.cpp b/test/test_mock.cpp index 3fb9397..34d0325 100644 --- a/test/test_mock.cpp +++ b/test/test_mock.cpp @@ -9,7 +9,6 @@ #include "mock_error.hpp" #include #include -#include #include namespace