From c359af3141f081d9e6da81de3e23d70d84fc7722 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 4 Feb 2022 21:34:14 +0200 Subject: [PATCH] Update system_error constructors --- include/boost/system/system_error.hpp | 45 +++++++-------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/include/boost/system/system_error.hpp b/include/boost/system/system_error.hpp index 7b20cd9..09d65e2 100644 --- a/include/boost/system/system_error.hpp +++ b/include/boost/system/system_error.hpp @@ -23,46 +23,25 @@ private: error_code code_; -private: - - static std::string build_message( char const * prefix, error_code const & ec ) - { - std::string r; - - if( prefix ) - { - r += prefix; - r += ": "; - } - - r += ec.what(); - return r; - } - - static std::string build_message( char const * prefix, int ev, error_category const & cat ) - { - return build_message( prefix, error_code( ev, cat ) ); - } - public: - explicit system_error( error_code const & ec ) - : std::runtime_error( build_message( 0, ec ) ), code_( ec ) {} + explicit system_error( error_code const & ec ): + std::runtime_error( ec.what() ), code_( ec ) {} - system_error( error_code const & ec, std::string const & prefix ) - : std::runtime_error( build_message( prefix.c_str(), ec ) ), code_( ec ) {} + system_error( error_code const & ec, std::string const & prefix ): + std::runtime_error( prefix + ": " + ec.what() ), code_( ec ) {} - system_error( error_code const & ec, char const * prefix ) - : std::runtime_error( build_message( prefix, ec ) ), code_( ec ) {} + system_error( error_code const & ec, char const * prefix ): + std::runtime_error( std::string( prefix ) + ": " + ec.what() ), code_( ec ) {} - system_error( int ev, error_category const & ecat ) - : std::runtime_error( build_message( 0, ev, ecat ) ), code_( ev, ecat ) {} + system_error( int ev, error_category const & ecat ): + std::runtime_error( error_code( ev, ecat ).what() ), code_( ev, ecat ) {} - system_error( int ev, error_category const & ecat, std::string const & prefix ) - : std::runtime_error( build_message( prefix.c_str(), ev, ecat ) ), code_( ev, ecat ) {} + system_error( int ev, error_category const & ecat, std::string const & prefix ): + std::runtime_error( prefix + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {} - system_error( int ev, error_category const & ecat, char const * prefix ) - : std::runtime_error( build_message( prefix, ev, ecat ) ), code_( ev, ecat ) {} + system_error( int ev, error_category const & ecat, char const * prefix ): + std::runtime_error( std::string( prefix ) + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {} error_code code() const BOOST_NOEXCEPT {