// (C) Copyright Gennadiy Rozental 2011-2014. // 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) // See http://www.boost.org/libs/test for the library home page. // // File : $RCSfile$ // // Version : $Revision: 74248 $ // // Description : defines level of indiration facilitating workarounds for non printable types // *************************************************************************** #ifndef BOOST_TEST_TOOLS_IMPL_COMMON_HPP_012705GER #define BOOST_TEST_TOOLS_IMPL_COMMON_HPP_012705GER // Boost.Test #include #include #include // Boost #include #include #include #include #include #include //____________________________________________________________________________// namespace boost { namespace test_tools { namespace tt_detail { // ************************************************************************** // // ************** print_log_value ************** // // ************************************************************************** // template struct print_log_value { void operator()( std::ostream& ostr, T const& t ) { typedef typename mpl::or_,is_function,is_abstract >::type cant_use_nl; std::streamsize old_precision = set_precision( ostr, cant_use_nl() ); ostr << t; if( old_precision != (std::streamsize)-1 ) ostr.precision( old_precision ); } std::streamsize set_precision( std::ostream& ostr, mpl::false_ ) { if( std::numeric_limits::is_specialized && std::numeric_limits::radix == 2 ) return ostr.precision( 2 + std::numeric_limits::digits * 301/1000 ); else if ( std::numeric_limits::is_specialized && std::numeric_limits::radix == 10 ) { #ifdef BOOST_NO_CXX11_NUMERIC_LIMITS // (was BOOST_NO_NUMERIC_LIMITS_LOWEST but now deprecated). // No support for std::numeric_limits::max_digits10, // so guess that a couple of guard digits more than digits10 will display any difference. return ostr.precision( 2 + std::numeric_limits::digits10 ); #else // std::numeric_limits::max_digits10; IS supported. // Any noisy or guard digits needed to display any difference are included in max_digits10. return ostr.precision( std::numeric_limits::max_digits10 ); #endif } // else if T is not specialized for std::numeric_limits<>, // then will just get the default precision of 6 digits. return (std::streamsize)-1; } std::streamsize set_precision( std::ostream&, mpl::true_ ) { return (std::streamsize)-1; } }; //____________________________________________________________________________// #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) template struct print_log_value< T[N] > { void operator()( std::ostream& ostr, T const* t ) { ostr << t; } }; #endif //____________________________________________________________________________// template<> struct BOOST_TEST_DECL print_log_value { void operator()( std::ostream& ostr, bool t ) { ostr << std::boolalpha << t; } }; //____________________________________________________________________________// template<> struct BOOST_TEST_DECL print_log_value { void operator()( std::ostream& ostr, char t ); }; //____________________________________________________________________________// template<> struct BOOST_TEST_DECL print_log_value { void operator()( std::ostream& ostr, unsigned char t ); }; //____________________________________________________________________________// template<> struct BOOST_TEST_DECL print_log_value { void operator()( std::ostream& ostr, char const* t ); }; //____________________________________________________________________________// template<> struct BOOST_TEST_DECL print_log_value { void operator()( std::ostream& ostr, wchar_t const* t ); }; //____________________________________________________________________________// // ************************************************************************** // // ************** print_helper ************** // // ************************************************************************** // // Adds level of indirection to the output operation, allowing us to customize // it for types that do not support operator << directly or for any other reason template struct print_helper_t { explicit print_helper_t( T const& t ) : m_t( t ) {} T const& m_t; }; //____________________________________________________________________________// #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // Borland suffers premature pointer decay passing arrays by reference template struct print_helper_t< T[N] > { explicit print_helper_t( T const * t ) : m_t( t ) {} T const * m_t; }; #endif //____________________________________________________________________________// template inline print_helper_t print_helper( T const& t ) { return print_helper_t( t ); } //____________________________________________________________________________// template inline std::ostream& operator<<( std::ostream& ostr, print_helper_t const& ph ) { print_log_value()( ostr, ph.m_t ); return ostr; } //____________________________________________________________________________// } // namespace tt_detail // ************************************************************************** // // ************** BOOST_TEST_DONT_PRINT_LOG_VALUE ************** // // ************************************************************************** // #define BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ) \ namespace boost{ namespace test_tools{ namespace tt_detail{ \ template<> \ struct print_log_value { \ void operator()( std::ostream&, the_type const& ) {} \ }; \ }}} \ /**/ } // namespace test_tools } // namespace boost #include #endif // BOOST_TEST_TOOLS_IMPL_COMMON_HPP_012705GER