#ifndef BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP #define BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP // MS compatible compilers support #pragma once #if defined(_MSC_VER) # pragma once #endif // boost/core/lightweight_test_trait.hpp // // BOOST_TEST_TRAIT_TRUE, BOOST_TEST_TRAIT_FALSE, BOOST_TEST_TRAIT_SAME // // Copyright 2014, 2021 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 #include #include #include #include namespace boost { namespace detail { template< class T > inline void test_trait_impl( char const * trait, void (*)( T ), bool expected, char const * file, int line, char const * function ) { if( T::value == expected ) { test_results(); } else { BOOST_LIGHTWEIGHT_TEST_OSTREAM << file << "(" << line << "): predicate '" << trait << "' [" << boost::core::type_name() << "]" << " test failed in function '" << function << "' (should have been " << ( expected? "true": "false" ) << ")" << std::endl; ++test_results().errors(); } } template inline bool test_trait_same_impl_( T ) { return T::value; } template inline void test_trait_same_impl( char const * types, boost::core::detail::is_same same, char const * file, int line, char const * function ) { if( test_trait_same_impl_( same ) ) { test_results(); } else { BOOST_LIGHTWEIGHT_TEST_OSTREAM << file << "(" << line << "): test 'is_same<" << types << ">'" << " failed in function '" << function << "' ('" << boost::core::type_name() << "' != '" << boost::core::type_name() << "')" << std::endl; ++test_results().errors(); } } } // namespace detail } // 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_FALSE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, false, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) ) #if defined(__GNUC__) // ignoring -Wvariadic-macros with #pragma doesn't work under GCC # pragma GCC system_header #endif #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) ) #endif // #ifndef BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP