/usr/include/boost/test/tools/detail
Edit: /usr/include/boost/test/tools/detail/print_helper.hpp (8536B)
// (C) Copyright Gennadiy Rozental 2001.
// 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
// Boost
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if !defined(BOOST_NO_CXX11_NULLPTR)
#include
#endif
#include
//____________________________________________________________________________//
namespace boost {
namespace test_tools {
namespace tt_detail {
// ************************************************************************** //
// ************** boost_test_print_type ************** //
// ************************************************************************** //
namespace impl {
template
std::ostream& boost_test_print_type(std::ostream& ostr, T const& t) {
BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift::value),
"Type has to implement operator<< to be printable");
ostr << t;
return ostr;
}
struct boost_test_print_type_impl {
template
std::ostream& operator()(std::ostream& ostr, R const& r) const {
return boost_test_print_type(ostr, r);
}
};
}
// To avoid ODR violations, see N4381
template struct static_const { static const T value; };
template const T static_const::value = T();
namespace {
static const impl::boost_test_print_type_impl& boost_test_print_type =
static_const::value;
}
// ************************************************************************** //
// ************** 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;
using boost::test_tools::tt_detail::boost_test_print_type;
boost_test_print_type(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(BOOST_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 );
};
//____________________________________________________________________________//
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 );
};
#if !defined(BOOST_NO_CXX11_NULLPTR)
template<>
struct print_log_value {
// declaration and definition is here because of #12969 https://svn.boost.org/trac10/ticket/12969
void operator()( std::ostream& ostr, std::nullptr_t /*t*/ ) {
ostr << "nullptr";
}
};
#endif
//____________________________________________________________________________//
// ************************************************************************** //
// ************** 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(BOOST_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