使用BOOST_TEST_TRAIT_SAME进行类型检查的实例
在C++中,我们经常需要检查两个类型是否相同,这时就可以使用BOOST_TEST_TRAIT_SAME宏。BOOST_TEST_TRAIT_SAME定义在boost/test/test_tools.hpp头文件中,用于检查两个类型是否相同。下面是一个简单的使用示例:
#include <boost/test/unit_test.hpp>
#include <boost/test/test_tools.hpp>
template<typename T, typename U>
struct is_same
{
static const bool value = false;
};
template
struct is_same<T, T>
{
static const bool value = true;
};
template<typename T, typename U>
void test_same()
{
BOOST_TEST_TRAIT_SAME(T, U);
BOOST_CHECK_EQUAL(is_same<T, U>::value, true);
}
BOOST_AUTO_TEST_CASE(test_boost_test_trait_s