File indexing completed on 2025-01-30 09:35:14
0001 #ifndef BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP
0002 #define BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP
0003
0004
0005
0006 #if defined(_MSC_VER)
0007 # pragma once
0008 #endif
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <boost/core/lightweight_test.hpp>
0024 #include <boost/core/type_name.hpp>
0025 #include <boost/core/detail/is_same.hpp>
0026 #include <boost/config.hpp>
0027
0028 namespace boost
0029 {
0030 namespace detail
0031 {
0032
0033 template< class T > inline void test_trait_impl( char const * trait, void (*)( T ),
0034 bool expected, char const * file, int line, char const * function )
0035 {
0036 if( T::value == expected )
0037 {
0038 test_results();
0039 }
0040 else
0041 {
0042 BOOST_LIGHTWEIGHT_TEST_OSTREAM
0043 << file << "(" << line << "): predicate '" << trait << "' ["
0044 << boost::core::type_name<T>() << "]"
0045 << " test failed in function '" << function
0046 << "' (should have been " << ( expected? "true": "false" ) << ")"
0047 << std::endl;
0048
0049 ++test_results().errors();
0050 }
0051 }
0052
0053 template<class T> inline bool test_trait_same_impl_( T )
0054 {
0055 return T::value;
0056 }
0057
0058 template<class T1, class T2> inline void test_trait_same_impl( char const * types,
0059 boost::core::detail::is_same<T1, T2> same, char const * file, int line, char const * function )
0060 {
0061 if( test_trait_same_impl_( same ) )
0062 {
0063 test_results();
0064 }
0065 else
0066 {
0067 BOOST_LIGHTWEIGHT_TEST_OSTREAM
0068 << file << "(" << line << "): test 'is_same<" << types << ">'"
0069 << " failed in function '" << function
0070 << "' ('" << boost::core::type_name<T1>()
0071 << "' != '" << boost::core::type_name<T2>() << "')"
0072 << std::endl;
0073
0074 ++test_results().errors();
0075 }
0076 }
0077
0078 }
0079 }
0080
0081 #define BOOST_TEST_TRAIT_TRUE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, true, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) )
0082 #define BOOST_TEST_TRAIT_FALSE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, false, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) )
0083
0084 #if defined(__GNUC__)
0085
0086 # pragma GCC system_header
0087 #endif
0088
0089 #define BOOST_TEST_TRAIT_SAME(...) ( ::boost::detail::test_trait_same_impl(#__VA_ARGS__, ::boost::core::detail::is_same< __VA_ARGS__ >(), __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) )
0090
0091 #endif