mirror of
https://github.com/boostorg/core.git
synced 2025-07-30 04:47:24 +02:00
Print type with cvref qualifiers
This commit is contained in:
@ -13,6 +13,9 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2014 Peter Dimov
|
// Copyright 2014 Peter Dimov
|
||||||
//
|
//
|
||||||
|
// Copyright 2019 Glen Joseph Fernandes
|
||||||
|
// (glenjofe@gmail.com)
|
||||||
|
//
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
@ -20,6 +23,7 @@
|
|||||||
#include <boost/core/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/core/typeinfo.hpp>
|
#include <boost/core/typeinfo.hpp>
|
||||||
#include <boost/core/is_same.hpp>
|
#include <boost/core/is_same.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@ -27,6 +31,50 @@ 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 )
|
||||||
{
|
{
|
||||||
@ -64,8 +112,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
|
||||||
<< "' ('" << boost::core::demangled_name( BOOST_CORE_TYPEID(T1) )
|
<< "' ('" << test_print<T1>()
|
||||||
<< "' != '" << boost::core::demangled_name( BOOST_CORE_TYPEID(T2) ) << "')"
|
<< "' != '" << test_print<T2>() << "')"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
++test_results().errors();
|
++test_results().errors();
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
#include <boost/core/lightweight_test_trait.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
struct X
|
struct X
|
||||||
{
|
{
|
||||||
@ -20,6 +21,21 @@ template<class T1, class T2> struct Y
|
|||||||
typedef T1 type;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
BOOST_TEST_TRAIT_SAME(char[1], char[2]);
|
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, Y<void, void>);
|
||||||
BOOST_TEST_TRAIT_SAME(X::type, Y<float, int>::type);
|
BOOST_TEST_TRAIT_SAME(X::type, Y<float, int>::type);
|
||||||
BOOST_TEST_TRAIT_SAME(Y<int, float>, Y<int, double>);
|
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user