// comment out to disable #define ASSERT_USE_BOOST_STATIC_ASSERT #define ASSERT_USE_BOOST_MPL_ASSERT #define ASSERT_USE_BOOST_MPL_ASSERT_MSG #define ASSERT_USE_KUODO_TYPES_ASSERT #define ASSERT_USE_KUODO_TYPES_TYPE_ASSERT // comment out to not assert #define ASSERT_NAMESPACE #define ASSERT_FUNCTION #define ASSERT_CLASS #define ASSERT_MEMBER_FUNCTION #define ASSERT_DEEP #include #include #include #include "assert.hpp" //BOOST_STATIC_ASSERT #ifdef ASSERT_USE_BOOST_STATIC_ASSERT #include #define ASSERT_BOOST_STATIC_ASSERT(a) BOOST_STATIC_ASSERT(a) #else #define ASSERT_BOOST_STATIC_ASSERT(a) typedef void no_boost_static_assert #endif //BOOST_MPL_ASSERT #ifdef ASSERT_USE_BOOST_MPL_ASSERT #include #define ASSERT_BOOST_MPL_ASSERT(a) BOOST_MPL_ASSERT(a) #else #define ASSERT_BOOST_MPL_ASSERT(a) typedef void no_boost_mpl_assert #endif //BOOST_MPL_ASSERT_MSG #ifdef ASSERT_USE_BOOST_MPL_ASSERT_MSG #include #define ASSERT_BOOST_MPL_ASSERT_MSG(a, b, c) BOOST_MPL_ASSERT_MSG(a, b, c) #else #define ASSERT_BOOST_MPL_ASSERT_MSG(a, b, c) typedef void no_boost_mpl_assert_msg #endif namespace tests { //kuodo::types::assert #ifdef ASSERT_USE_KUODO_TYPES_ASSERT using kuodo::types::assert; #else template struct assert {}; #endif //kuodo::types::type_assert #ifdef ASSERT_USE_KUODO_TYPES_TYPE_ASSERT using kuodo::types::type_assert; #else template struct type_assert {}; #endif using kuodo::types::assertion; template struct bool_value { static bool const value = value_; typedef bool value_type; typedef bool_value type; operator bool() const { return value_; } }; template bool const bool_value::value; // namespace scope ///////////////////////////////////////////////////////////////////// bool const namespace_assert_if = #ifdef ASSERT_NAMESPACE false; #else true; #endif template struct namespace_assert : assertion {}; ASSERT_BOOST_STATIC_ASSERT(namespace_assert_if); ASSERT_BOOST_MPL_ASSERT((bool_value)); ASSERT_BOOST_MPL_ASSERT_MSG(namespace_assert_if, NAMESPACE_ASSERT, (int)); typedef assert assert_1; typedef type_assert > assert_2; // function scope ///////////////////////////////////////////////////////////////////// template struct is_pointer : bool_value {}; template struct is_pointer : bool_value {}; template struct not_pointer : assertion::value> {}; template int function(type_ const&) { ASSERT_BOOST_STATIC_ASSERT(is_pointer::value); ASSERT_BOOST_MPL_ASSERT((is_pointer)); ASSERT_BOOST_MPL_ASSERT_MSG((is_pointer::value), NOT_POINTER, (type_)); typedef assert::value> assert_1; typedef type_assert > assert_2; return 0; } int use_function = #ifdef ASSERT_FUNCTION function(std::vector()); #else function(static_cast(0)); #endif // class scope ///////////////////////////////////////////////////////////////////// bool test_random_access(std::random_access_iterator_tag const*); bool (&test_random_access(void const*))[2]; template struct is_random_access : bool_value< //use ::tests::test_random... or gcc 3.3 sizeof(::tests::test_random_access(static_cast(0))) == sizeof(true) > {}; template class class_scope { typedef typename std::iterator_traits::iterator_category category_type; template struct not_random_access : assertion::value> {}; ASSERT_BOOST_STATIC_ASSERT(is_random_access::value); ASSERT_BOOST_MPL_ASSERT((is_random_access)); ASSERT_BOOST_MPL_ASSERT_MSG((is_random_access::value), NOT_RANDOM_ACCESS, (iterator_, category_type)); typedef assert::value> assert_1; typedef type_assert > assert_2; }; #ifdef ASSERT_CLASS class_scope::iterator> use_class_scope; #else class_scope::iterator> use_class_scope; #endif // class member function scope ///////////////////////////////////////////////////////////////////// template class member_function { //typedef typename std::iterator_traits::iterator_category category_type; template struct not_random_access : assertion::value> {}; public: int function() const { //with boost 1.33.0 and codewarrior 10 (mac): //BOOST_MPL_ASSERT_MSG on does not work if category_type is private to the class typedef typename std::iterator_traits::iterator_category category_type; ASSERT_BOOST_STATIC_ASSERT(is_random_access::value); ASSERT_BOOST_MPL_ASSERT((is_random_access)); ASSERT_BOOST_MPL_ASSERT_MSG((is_random_access::value), NOT_RANDOM_ACCESS, (iterator_, category_type)); typedef assert::value> assert_1; typedef type_assert > assert_2; return 0; } }; int use_member_function = #ifdef ASSERT_MEMBER_FUNCTION member_function::iterator>().function(); #else member_function::iterator>().function(); #endif } //namespace tests int main(int /*argc*/, char** /*argv*/) { return 0; }