From 446098fd8a7df783c8d063e26a085f77a9b018a8 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 20 Oct 2020 17:52:33 -0700 Subject: [PATCH] Trimmed down standard includes: - no longer including , using instead - under BOOST_LEAF_DIAGNOSTICS=0, no longer including and --- include/boost/leaf.hpp | 66 +++++++++++++++----------- include/boost/leaf/capture.hpp | 4 +- include/boost/leaf/common.hpp | 6 ++- include/boost/leaf/detail/demangle.hpp | 7 +-- include/boost/leaf/detail/print.hpp | 2 +- include/boost/leaf/error.hpp | 28 +++++++---- include/boost/leaf/handle_errors.hpp | 18 ++++--- include/boost/leaf/result.hpp | 1 - test/defer_basic_test.cpp | 1 + test/preload_basic_test.cpp | 1 + 10 files changed, 80 insertions(+), 54 deletions(-) diff --git a/include/boost/leaf.hpp b/include/boost/leaf.hpp index 94cf84b..48e66cf 100644 --- a/include/boost/leaf.hpp +++ b/include/boost/leaf.hpp @@ -870,7 +870,7 @@ namespace boost { namespace leaf { #endif // <<< #include #line 20 "boost/leaf/detail/print.hpp" -#include +#include #include namespace boost { namespace leaf { @@ -989,9 +989,12 @@ namespace boost { namespace leaf { #line 21 "boost/leaf/error.hpp" #include #include -#include #include -#include + +#if BOOST_LEAF_DIAGNOSTICS +# include +# include +#endif #define BOOST_LEAF_TOKEN_PASTE(x, y) x ## y #define BOOST_LEAF_TOKEN_PASTE2(x, y) BOOST_LEAF_TOKEN_PASTE(x, y) @@ -1113,7 +1116,8 @@ namespace boost { namespace leaf { { } - void print(std::ostream & os) const + template + void print( std::basic_ostream & os ) const { BOOST_LEAF_ASSERT(first_type != 0); BOOST_LEAF_ASSERT(count>0); @@ -1122,7 +1126,7 @@ namespace boost { namespace leaf { os << "1 attempt to communicate an unexpected error object"; else os << count << " attempts to communicate unexpected error objects, the first one"; - os << " of type " << first_type() << std::endl; + (os << " of type " << first_type() << '\n').flush(); } }; @@ -1151,12 +1155,13 @@ namespace boost { namespace leaf { { std::stringstream s; diagnostic::print(s,e); - s << std::endl; + (s << '\n').flush(); s_ += s.str(); } } - void print(std::ostream & os) const + template + void print( std::basic_ostream & os ) const { os << "Unhandled error objects:\n" << s_; } @@ -1193,7 +1198,8 @@ namespace boost { namespace leaf { int const line; char const * const function; - friend std::ostream & operator<<( std::ostream & os, e_source_location const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, e_source_location const & x ) { return os << leaf::type() << ": " << x.file << '(' << x.line << ") in function " << x.function; } @@ -1256,7 +1262,8 @@ namespace boost { namespace leaf { BOOST_LEAF_CONSTEXPR void propagate() noexcept; - void print( std::ostream & os, int key_to_print ) const + template + void print( std::basic_ostream & os, int key_to_print ) const { if( !diagnostic::is_invisible ) if( int k = this->key() ) @@ -1269,7 +1276,7 @@ namespace boost { namespace leaf { else os << '[' << k << ']'; diagnostic::print(os, value(k)); - os << std::endl; + (os << '\n').flush(); } } @@ -1590,7 +1597,8 @@ namespace boost { namespace leaf { return a.value_ < b.value_; } - friend std::ostream & operator<<( std::ostream & os, error_id x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, error_id x ) { return os << x.value_; } @@ -2122,7 +2130,6 @@ namespace boost { namespace leaf { #endif // <<< #include #line 21 "boost/leaf/capture.hpp" -#include namespace boost { namespace leaf { @@ -2219,7 +2226,8 @@ namespace boost { namespace leaf { std::rethrow_exception(ex_); } - void print( std::ostream & os ) const + template + void print( std::basic_ostream & os ) const { ctx_->print(os); } @@ -2447,7 +2455,8 @@ namespace boost { namespace leaf { { int value; - friend std::ostream & operator<<( std::ostream & os, e_errno const & err ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, e_errno const & err ) { return os << type() << ": " << err.value << ", \"" << std::strerror(err.value) << '"'; } @@ -2464,7 +2473,8 @@ namespace boost { namespace leaf { unsigned value; #ifdef _WIN32 - friend std::ostream & operator<<( std::ostream & os, e_LastError const & err ) + template + friend std::basic_ostream & operator<<( std::basic_ostream os, e_LastError const & err ) { struct msg_buf { @@ -3016,8 +3026,6 @@ namespace boost { namespace leaf { # endif #endif -#include - #if !defined(_MSC_VER) # if defined(__has_include) && __has_include() # define BOOST_LEAF_HAS_CXXABI_H @@ -3032,7 +3040,6 @@ namespace boost { namespace leaf { # if defined( __GABIXX_CXXABI_H__ ) # undef BOOST_LEAF_HAS_CXXABI_H # else -# include # include # endif #endif @@ -3085,7 +3092,7 @@ namespace boost { namespace leaf { std::free( const_cast< char* >( name ) ); } - inline std::string demangle( char const * name ) + inline char const * demangle( char const * name ) { scoped_demangled_name demangled_name( name ); char const * p = demangled_name.get(); @@ -3105,7 +3112,7 @@ namespace boost { namespace leaf { { } - inline std::string demangle( char const * name ) + inline char const * demangle( char const * name ) { return name; } @@ -3153,7 +3160,8 @@ namespace boost { namespace leaf { error_info( error_info const & ) noexcept = default; - void print( std::ostream & os ) const + template + void print( std::basic_ostream & os ) const { os << "Error ID = " << err_id_.value(); #ifndef BOOST_LEAF_NO_EXCEPTIONS @@ -3198,7 +3206,8 @@ namespace boost { namespace leaf { #endif } - friend std::ostream & operator<<( std::ostream & os, error_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, error_info const & x ) { os << "leaf::error_info: "; x.print(os); @@ -3231,7 +3240,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { os << "leaf::diagnostic_info for "; x.print(os); @@ -3280,7 +3290,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { os << "leaf::diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1\n" @@ -3338,7 +3349,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, verbose_diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, verbose_diagnostic_info const & x ) { os << "leaf::verbose_diagnostic_info for "; x.print(os); @@ -3387,7 +3399,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, verbose_diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, verbose_diagnostic_info const & x ) { os << "leaf::verbose_diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1\n" @@ -4283,7 +4296,6 @@ namespace boost { namespace leaf { # endif #endif -#include #include namespace boost { namespace leaf { diff --git a/include/boost/leaf/capture.hpp b/include/boost/leaf/capture.hpp index 9f160ab..8690683 100644 --- a/include/boost/leaf/capture.hpp +++ b/include/boost/leaf/capture.hpp @@ -18,7 +18,6 @@ #include #include -#include namespace boost { namespace leaf { @@ -115,7 +114,8 @@ namespace boost { namespace leaf { std::rethrow_exception(ex_); } - void print( std::ostream & os ) const + template + void print( std::basic_ostream & os ) const { ctx_->print(os); } diff --git a/include/boost/leaf/common.hpp b/include/boost/leaf/common.hpp index be50a52..e4252f5 100644 --- a/include/boost/leaf/common.hpp +++ b/include/boost/leaf/common.hpp @@ -40,7 +40,8 @@ namespace boost { namespace leaf { { int value; - friend std::ostream & operator<<( std::ostream & os, e_errno const & err ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, e_errno const & err ) { return os << type() << ": " << err.value << ", \"" << std::strerror(err.value) << '"'; } @@ -57,7 +58,8 @@ namespace boost { namespace leaf { unsigned value; #ifdef _WIN32 - friend std::ostream & operator<<( std::ostream & os, e_LastError const & err ) + template + friend std::basic_ostream & operator<<( std::basic_ostream os, e_LastError const & err ) { struct msg_buf { diff --git a/include/boost/leaf/detail/demangle.hpp b/include/boost/leaf/detail/demangle.hpp index eedb06d..4622564 100644 --- a/include/boost/leaf/detail/demangle.hpp +++ b/include/boost/leaf/detail/demangle.hpp @@ -25,8 +25,6 @@ # endif #endif -#include - #if !defined(_MSC_VER) # if defined(__has_include) && __has_include() # define BOOST_LEAF_HAS_CXXABI_H @@ -41,7 +39,6 @@ # if defined( __GABIXX_CXXABI_H__ ) # undef BOOST_LEAF_HAS_CXXABI_H # else -# include # include # endif #endif @@ -94,7 +91,7 @@ namespace boost { namespace leaf { std::free( const_cast< char* >( name ) ); } - inline std::string demangle( char const * name ) + inline char const * demangle( char const * name ) { scoped_demangled_name demangled_name( name ); char const * p = demangled_name.get(); @@ -114,7 +111,7 @@ namespace boost { namespace leaf { { } - inline std::string demangle( char const * name ) + inline char const * demangle( char const * name ) { return name; } diff --git a/include/boost/leaf/detail/print.hpp b/include/boost/leaf/detail/print.hpp index 2b349a4..cc6aa00 100644 --- a/include/boost/leaf/detail/print.hpp +++ b/include/boost/leaf/detail/print.hpp @@ -17,7 +17,7 @@ #endif #include -#include +#include #include namespace boost { namespace leaf { diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index dd7fd55..bf9aa38 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -20,9 +20,12 @@ #include #include #include -#include #include -#include + +#if BOOST_LEAF_DIAGNOSTICS +# include +# include +#endif #define BOOST_LEAF_TOKEN_PASTE(x, y) x ## y #define BOOST_LEAF_TOKEN_PASTE2(x, y) BOOST_LEAF_TOKEN_PASTE(x, y) @@ -144,7 +147,8 @@ namespace boost { namespace leaf { { } - void print(std::ostream & os) const + template + void print( std::basic_ostream & os ) const { BOOST_LEAF_ASSERT(first_type != 0); BOOST_LEAF_ASSERT(count>0); @@ -153,7 +157,7 @@ namespace boost { namespace leaf { os << "1 attempt to communicate an unexpected error object"; else os << count << " attempts to communicate unexpected error objects, the first one"; - os << " of type " << first_type() << std::endl; + (os << " of type " << first_type() << '\n').flush(); } }; @@ -182,12 +186,13 @@ namespace boost { namespace leaf { { std::stringstream s; diagnostic::print(s,e); - s << std::endl; + (s << '\n').flush(); s_ += s.str(); } } - void print(std::ostream & os) const + template + void print( std::basic_ostream & os ) const { os << "Unhandled error objects:\n" << s_; } @@ -224,7 +229,8 @@ namespace boost { namespace leaf { int const line; char const * const function; - friend std::ostream & operator<<( std::ostream & os, e_source_location const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, e_source_location const & x ) { return os << leaf::type() << ": " << x.file << '(' << x.line << ") in function " << x.function; } @@ -287,7 +293,8 @@ namespace boost { namespace leaf { BOOST_LEAF_CONSTEXPR void propagate() noexcept; - void print( std::ostream & os, int key_to_print ) const + template + void print( std::basic_ostream & os, int key_to_print ) const { if( !diagnostic::is_invisible ) if( int k = this->key() ) @@ -300,7 +307,7 @@ namespace boost { namespace leaf { else os << '[' << k << ']'; diagnostic::print(os, value(k)); - os << std::endl; + (os << '\n').flush(); } } @@ -621,7 +628,8 @@ namespace boost { namespace leaf { return a.value_ < b.value_; } - friend std::ostream & operator<<( std::ostream & os, error_id x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, error_id x ) { return os << x.value_; } diff --git a/include/boost/leaf/handle_errors.hpp b/include/boost/leaf/handle_errors.hpp index fe67c85..2e12a07 100644 --- a/include/boost/leaf/handle_errors.hpp +++ b/include/boost/leaf/handle_errors.hpp @@ -50,7 +50,8 @@ namespace boost { namespace leaf { error_info( error_info const & ) noexcept = default; - void print( std::ostream & os ) const + template + void print( std::basic_ostream & os ) const { os << "Error ID = " << err_id_.value(); #ifndef BOOST_LEAF_NO_EXCEPTIONS @@ -95,7 +96,8 @@ namespace boost { namespace leaf { #endif } - friend std::ostream & operator<<( std::ostream & os, error_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, error_info const & x ) { os << "leaf::error_info: "; x.print(os); @@ -128,7 +130,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { os << "leaf::diagnostic_info for "; x.print(os); @@ -177,7 +180,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { os << "leaf::diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1\n" @@ -235,7 +239,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, verbose_diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, verbose_diagnostic_info const & x ) { os << "leaf::verbose_diagnostic_info for "; x.print(os); @@ -284,7 +289,8 @@ namespace boost { namespace leaf { public: - friend std::ostream & operator<<( std::ostream & os, verbose_diagnostic_info const & x ) + template + friend std::basic_ostream & operator<<( std::basic_ostream & os, verbose_diagnostic_info const & x ) { os << "leaf::verbose_diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1\n" diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index b6bfc9c..bef9315 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -17,7 +17,6 @@ #endif #include -#include #include namespace boost { namespace leaf { diff --git a/test/defer_basic_test.cpp b/test/defer_basic_test.cpp index 52393ca..330d4ce 100644 --- a/test/defer_basic_test.cpp +++ b/test/defer_basic_test.cpp @@ -7,6 +7,7 @@ #include #include #include "lightweight_test.hpp" +#include namespace leaf = boost::leaf; diff --git a/test/preload_basic_test.cpp b/test/preload_basic_test.cpp index a3b26ed..a0c9d3a 100644 --- a/test/preload_basic_test.cpp +++ b/test/preload_basic_test.cpp @@ -7,6 +7,7 @@ #include #include #include "lightweight_test.hpp" +#include namespace leaf = boost::leaf;