Print type with cvref qualifiers

This commit is contained in:
Glen Fernandes 2019-04-20 03:04:06 -04:00
parent 02041f6c9f
commit a78c25e4ab
2 changed files with 75 additions and 3 deletions

View File

@ -13,6 +13,9 @@
//
// Copyright 2014 Peter Dimov
//
// Copyright 2019 Glen Joseph Fernandes
// (glenjofe@gmail.com)
//
// 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
@ -20,6 +23,7 @@
#include <boost/core/lightweight_test.hpp>
#include <boost/core/typeinfo.hpp>
#include <boost/core/is_same.hpp>
#include <boost/config.hpp>
namespace boost
{
@ -27,6 +31,50 @@ namespace boost
namespace detail
{
template<class, int = 0> struct test_print { };
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<T, 2>)
{
return o << boost::core::demangled_name(BOOST_CORE_TYPEID(T));
}
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<T, 1>)
{
return o << test_print<T, 2>();
}
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<const T, 1>)
{
return o << test_print<T, 2>() << " const";
}
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<volatile T, 1>)
{
return o << test_print<T, 2>() << " volatile";
}
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<const volatile T, 1>)
{
return o << test_print<T, 2>() << " const volatile";
}
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<T>)
{
return o << test_print<T, 1>();
}
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<T&>)
{
return o << test_print<T, 1>() << " &";
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<class T> inline std::ostream& operator<<(std::ostream& o, test_print<T&&>)
{
return o << test_print<T, 1>() << " &&";
}
#endif
template< class T > inline void test_trait_impl( char const * trait, void (*)( T ),
bool expected, char const * file, int line, char const * function )
{
@ -64,8 +112,8 @@ template<class T1, class T2> inline void test_trait_same_impl( char const * type
BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): test 'is_same<" << types << ">'"
<< " failed in function '" << function
<< "' ('" << boost::core::demangled_name( BOOST_CORE_TYPEID(T1) )
<< "' != '" << boost::core::demangled_name( BOOST_CORE_TYPEID(T2) ) << "')"
<< "' ('" << test_print<T1>()
<< "' != '" << test_print<T2>() << "')"
<< std::endl;
++test_results().errors();

View File

@ -9,6 +9,7 @@
//
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
struct X
{
@ -20,6 +21,21 @@ template<class T1, class T2> struct Y
typedef T1 type;
};
typedef int I1;
typedef const int I2;
typedef volatile int I3;
typedef const volatile int I4;
typedef int& I5;
typedef const int& I6;
typedef volatile int& I7;
typedef const volatile int& I8;
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
typedef int&& I9;
typedef const int&& I10;
typedef volatile int&& I11;
typedef const volatile int&& I12;
#endif
int main()
{
BOOST_TEST_TRAIT_SAME(char[1], char[2]);
@ -32,6 +48,14 @@ int main()
BOOST_TEST_TRAIT_SAME(X, Y<void, void>);
BOOST_TEST_TRAIT_SAME(X::type, Y<float, int>::type);
BOOST_TEST_TRAIT_SAME(Y<int, float>, Y<int, double>);
BOOST_TEST_TRAIT_SAME(I1, I2);
BOOST_TEST_TRAIT_SAME(I3, I4);
BOOST_TEST_TRAIT_SAME(I5, I6);
BOOST_TEST_TRAIT_SAME(I7, I8);
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST_TRAIT_SAME(I9, I10);
BOOST_TEST_TRAIT_SAME(I11, I12);
#endif
return boost::report_errors() == 10;
return boost::report_errors() == 16;
}