Use core::type_name in lightweight_test_trait

This commit is contained in:
Peter Dimov
2021-10-05 04:58:52 +03:00
parent 5e382efa84
commit 290340fd27

View File

@@ -11,7 +11,7 @@
// //
// BOOST_TEST_TRAIT_TRUE, BOOST_TEST_TRAIT_FALSE, BOOST_TEST_TRAIT_SAME // BOOST_TEST_TRAIT_TRUE, BOOST_TEST_TRAIT_FALSE, BOOST_TEST_TRAIT_SAME
// //
// Copyright 2014 Peter Dimov // Copyright 2014, 2021 Peter Dimov
// //
// Copyright 2019 Glen Joseph Fernandes // Copyright 2019 Glen Joseph Fernandes
// (glenjofe@gmail.com) // (glenjofe@gmail.com)
@@ -21,60 +21,15 @@
// http://www.boost.org/LICENSE_1_0.txt // http://www.boost.org/LICENSE_1_0.txt
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <boost/core/typeinfo.hpp> #include <boost/core/type_name.hpp>
#include <boost/core/is_same.hpp> #include <boost/core/is_same.hpp>
#include <boost/config.hpp> #include <boost/config.hpp>
namespace boost namespace boost
{ {
namespace detail 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 ), template< class T > inline void test_trait_impl( char const * trait, void (*)( T ),
bool expected, char const * file, int line, char const * function ) bool expected, char const * file, int line, char const * function )
{ {
@@ -86,7 +41,7 @@ template< class T > inline void test_trait_impl( char const * trait, void (*)( T
{ {
BOOST_LIGHTWEIGHT_TEST_OSTREAM BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): predicate '" << trait << "' [" << file << "(" << line << "): predicate '" << trait << "' ["
<< boost::core::demangled_name( BOOST_CORE_TYPEID(T) ) << "]" << boost::core::type_name<T>() << "]"
<< " test failed in function '" << function << " test failed in function '" << function
<< "' (should have been " << ( expected? "true": "false" ) << ")" << "' (should have been " << ( expected? "true": "false" ) << ")"
<< std::endl; << std::endl;
@@ -112,8 +67,8 @@ template<class T1, class T2> inline void test_trait_same_impl( char const * type
BOOST_LIGHTWEIGHT_TEST_OSTREAM BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): test 'is_same<" << types << ">'" << file << "(" << line << "): test 'is_same<" << types << ">'"
<< " failed in function '" << function << " failed in function '" << function
<< "' ('" << test_print<T1>() << "' ('" << boost::core::type_name<T1>()
<< "' != '" << test_print<T2>() << "')" << "' != '" << boost::core::type_name<T2>() << "')"
<< std::endl; << std::endl;
++test_results().errors(); ++test_results().errors();
@@ -121,7 +76,6 @@ template<class T1, class T2> inline void test_trait_same_impl( char const * type
} }
} // namespace detail } // namespace detail
} // namespace boost } // namespace boost
#define BOOST_TEST_TRAIT_TRUE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, true, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) ) #define BOOST_TEST_TRAIT_TRUE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, true, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) )