summaryrefslogtreecommitdiff
path: root/boost/test/tools/detail/print_helper.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/test/tools/detail/print_helper.hpp')
-rw-r--r--boost/test/tools/detail/print_helper.hpp54
1 files changed, 46 insertions, 8 deletions
diff --git a/boost/test/tools/detail/print_helper.hpp b/boost/test/tools/detail/print_helper.hpp
index 39ab707f36..1e4dd6e3c0 100644
--- a/boost/test/tools/detail/print_helper.hpp
+++ b/boost/test/tools/detail/print_helper.hpp
@@ -30,6 +30,10 @@
#include <limits>
+#if !defined(BOOST_NO_CXX11_NULLPTR)
+#include <cstddef>
+#endif
+
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
@@ -39,21 +43,51 @@ namespace test_tools {
namespace tt_detail {
// ************************************************************************** //
+// ************** boost_test_print_type ************** //
+// ************************************************************************** //
+
+ namespace impl {
+ template <class T>
+ std::ostream& boost_test_print_type(std::ostream& ostr, T const& t) {
+ BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift<std::ostream,T>::value),
+ "Type has to implement operator<< to be printable");
+ ostr << t;
+ return ostr;
+ }
+
+ struct boost_test_print_type_impl {
+ template <class R>
+ std::ostream& operator()(std::ostream& ostr, R const& r) const {
+ return boost_test_print_type(ostr, r);
+ }
+ };
+ }
+
+ // To avoid ODR violations, see N4381
+ template <class T> struct static_const { static const T value; };
+ template <class T> const T static_const<T>::value = T();
+
+ namespace {
+ static const impl::boost_test_print_type_impl& boost_test_print_type =
+ static_const<impl::boost_test_print_type_impl>::value;
+ }
+
+
+// ************************************************************************** //
// ************** print_log_value ************** //
// ************************************************************************** //
template<typename T>
struct print_log_value {
- BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift<std::ostream,T>::value),
- "Type has to implement operator<< to be printable");
-
void operator()( std::ostream& ostr, T const& t )
{
typedef typename mpl::or_<is_array<T>,is_function<T>,is_abstract<T> >::type cant_use_nl;
std::streamsize old_precision = set_precision( ostr, cant_use_nl() );
- ostr << t;
+ //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 );
@@ -99,10 +133,7 @@ struct print_log_value< T[N] > {
template<>
struct BOOST_TEST_DECL print_log_value<bool> {
- void operator()( std::ostream& ostr, bool t )
- {
- ostr << std::boolalpha << t;
- }
+ void operator()( std::ostream& ostr, bool t );
};
//____________________________________________________________________________//
@@ -133,6 +164,13 @@ struct BOOST_TEST_DECL print_log_value<wchar_t const*> {
void operator()( std::ostream& ostr, wchar_t const* t );
};
+#if !defined(BOOST_NO_CXX11_NULLPTR)
+template<>
+struct BOOST_TEST_DECL print_log_value<std::nullptr_t> {
+ void operator()( std::ostream& ostr, std::nullptr_t t );
+};
+#endif
+
//____________________________________________________________________________//
// ************************************************************************** //