diff --git a/include/boost/type_index/type_index_base.hpp b/include/boost/type_index/type_index_base.hpp index 2e40862..6cc0800 100644 --- a/include/boost/type_index/type_index_base.hpp +++ b/include/boost/type_index/type_index_base.hpp @@ -96,6 +96,70 @@ inline bool operator != (const type_index_base& lhs, const type_index_ return !(lhs == rhs); } +// ######################### COMPARISONS with TypeInfo ############################ // +template +inline bool operator == (const TypeInfo& lhs, const type_index_base& rhs) BOOST_NOEXCEPT { + return type_index_base(lhs) == rhs; +} + +template +inline bool operator < (const TypeInfo& lhs, const type_index_base& rhs) BOOST_NOEXCEPT { + return type_index_base(lhs) < rhs; +} + +template +inline bool operator > (const TypeInfo& lhs, const type_index_base& rhs) BOOST_NOEXCEPT { + return rhs < type_index_base(lhs); +} + +template +inline bool operator <= (const TypeInfo& lhs, const type_index_base& rhs) BOOST_NOEXCEPT { + return !(type_index_base(lhs) > rhs); +} + +template +inline bool operator >= (const TypeInfo& lhs, const type_index_base& rhs) BOOST_NOEXCEPT { + return !(type_index_base(lhs) < rhs); +} + +template +inline bool operator != (const TypeInfo& lhs, const type_index_base& rhs) BOOST_NOEXCEPT { + return !(type_index_base(lhs) == rhs); +} + + +template +inline bool operator == (const type_index_base& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT { + return lhs == type_index_base(rhs); +} + +template +inline bool operator < (const type_index_base& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT { + return lhs < type_index_base(rhs); +} + +template +inline bool operator > (const type_index_base& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT { + return type_index_base(rhs) < lhs; +} + +template +inline bool operator <= (const type_index_base& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT { + return !(lhs > type_index_base(rhs)); +} + +template +inline bool operator >= (const type_index_base& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT { + return !(lhs < type_index_base(rhs)); +} + +template +inline bool operator != (const type_index_base& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT { + return !(lhs == type_index_base(rhs)); +} + +// ######################### COMPARISONS with TypeInfo END ############################ // + #ifndef BOOST_NO_IOSTREAM #ifdef BOOST_NO_TEMPLATED_IOSTREAMS diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index bab28af..118277c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -18,36 +18,34 @@ compat = BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY ; nortti = gcc:-fno-rtti clang:-fno-rtti msvc:/GR- ; -## Making libraries that CANNOT work between rtti-on/rtti-off modules +# Making libraries that CANNOT work between rtti-on/rtti-off modules #obj test_lib_nortti-obj : test_lib.cpp : shared off ; -#obj test_lib_rtti-obj : test_lib.cpp : shared ; -#lib test_lib_rtti : test_lib_rtti-obj : shared ; #lib test_lib_nortti : test_lib_nortti-obj : shared off ; -## Making libraries that can work between rtti-on/rtti-off modules -#obj test_lib_nortti_compat-obj : test_lib.cpp : shared $(nortti) $(compat) ; -#obj test_lib_rtti_compat-obj : test_lib.cpp : shared $(nortti) $(compat) ; -#lib test_lib_nortti_compat : test_lib_nortti_compat-obj : shared $(nortti) $(compat) ; -#lib test_lib_rtti_compat : test_lib_rtti_compat-obj : shared $(nortti) $(compat) ; +obj test_lib_rtti-obj : test_lib.cpp : shared ; +lib test_lib_rtti : test_lib_rtti-obj : shared ; + +# Making libraries that can work between rtti-on/rtti-off modules +obj test_lib_nortti_compat-obj : test_lib.cpp : shared $(nortti) $(compat) ; +obj test_lib_rtti_compat-obj : test_lib.cpp : shared $(nortti) $(compat) ; +lib test_lib_nortti_compat : test_lib_nortti_compat-obj : shared $(nortti) $(compat) ; +lib test_lib_rtti_compat : test_lib_rtti_compat-obj : shared $(nortti) $(compat) ; test-suite type_index : [ run type_index_test.cpp $(tlib) ] [ run type_index_test.cpp $(tlib) : : : off : type_index_test_no_rtti ] -# [ run template_index_test.cpp $(tlib) ] -# [ run testing_both.cpp $(tlib) ] -# [ run testing_both_no_rtti.cpp $(tlib) : : : off ] -# [ run testing_crossmodule.cpp test_lib_rtti $(tlib) ] + [ run testing_crossmodule.cpp test_lib_rtti $(tlib) ] # [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : off : testing_crossmodule_no_rtti ] -# # Mixing RTTI on and off -# [ link-fail testing_crossmodule.cpp $(tlib) test_lib_rtti : $(nortti) : link_fail_nortti_rtti ] -# # MSVC sometimes overrides the /GR-, that's why the following tests is disabled -# #[ link-fail testing_crossmodule.cpp $(tlib) test_lib_nortti : : link_fail_rtti_nortti ] -# [ run testing_crossmodule.cpp $(tlib) test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ] -# [ run testing_crossmodule.cpp $(tlib) test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ] -# + # Mixing RTTI on and off + [ link-fail testing_crossmodule.cpp $(tlib) test_lib_rtti : $(nortti) : link_fail_nortti_rtti ] + # MSVC sometimes overrides the /GR-, that's why the following tests is disabled + #[ link-fail testing_crossmodule.cpp $(tlib) test_lib_nortti : : link_fail_rtti_nortti ] + [ run testing_crossmodule.cpp $(tlib) test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ] + [ run testing_crossmodule.cpp $(tlib) test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ] + # # Examples that must work even with RTTI disabled # [ run ../examples/registry.cpp : : : off : registry_no_rtti ] # [ run ../examples/exact_types_match.cpp : : : off : exact_types_match_no_rtti ] diff --git a/test/test_lib.cpp b/test/test_lib.cpp index 85670bf..307298b 100644 --- a/test/test_lib.cpp +++ b/test/test_lib.cpp @@ -1,31 +1,33 @@ #define TEST_LIB_SOURCE #include "test_lib.hpp" +#include + namespace user_defined_namespace { class user_defined{}; } namespace test_lib { -boost::type_index get_integer() { - return boost::type_id(); +boost::typeind::type_index get_integer() { + return boost::typeind::type_id(); } -boost::type_index get_user_defined_class() { - return boost::type_id(); +boost::typeind::type_index get_user_defined_class() { + return boost::typeind::type_id(); } -boost::type_index get_const_integer() { - return boost::type_id_with_cvr(); +boost::typeind::type_index get_const_integer() { + return boost::typeind::type_id_with_cvr(); } -boost::type_index get_const_user_defined_class() { - return boost::type_id_with_cvr(); +boost::typeind::type_index get_const_user_defined_class() { + return boost::typeind::type_id_with_cvr(); } // Just do nothing -void accept_typeindex(const boost::type_index&) {} +void accept_typeindex(const boost::typeind::type_index&) {} } diff --git a/test/test_lib.hpp b/test/test_lib.hpp index 40528e8..37f52e7 100644 --- a/test/test_lib.hpp +++ b/test/test_lib.hpp @@ -25,14 +25,14 @@ namespace test_lib { -TEST_LIB_DECL boost::type_index get_integer(); -TEST_LIB_DECL boost::type_index get_user_defined_class(); +TEST_LIB_DECL boost::typeind::type_index get_integer(); +TEST_LIB_DECL boost::typeind::type_index get_user_defined_class(); -TEST_LIB_DECL boost::type_index get_const_integer(); -TEST_LIB_DECL boost::type_index get_const_user_defined_class(); +TEST_LIB_DECL boost::typeind::type_index get_const_integer(); +TEST_LIB_DECL boost::typeind::type_index get_const_user_defined_class(); // This is required for checking RTTI on/off linkage -TEST_LIB_DECL void accept_typeindex(const boost::type_index&); +TEST_LIB_DECL void accept_typeindex(const boost::typeind::type_index&); } diff --git a/test/testing_crossmodule.cpp b/test/testing_crossmodule.cpp index 106937e..675501d 100644 --- a/test/testing_crossmodule.cpp +++ b/test/testing_crossmodule.cpp @@ -8,7 +8,7 @@ #define BOOST_TEST_MODULE testing_crossmodule_module #include -#include +#include #include "test_lib.hpp" namespace user_defined_namespace { @@ -17,8 +17,8 @@ namespace user_defined_namespace { BOOST_AUTO_TEST_CASE(comparing_types_between_modules) { - boost::type_index t_const_int = boost::type_id_with_cvr(); - boost::type_index t_int = boost::type_id(); + boost::typeind::type_index t_const_int = boost::typeind::type_id_with_cvr(); + boost::typeind::type_index t_int = boost::typeind::type_id(); BOOST_CHECK_EQUAL(t_int, test_lib::get_integer()); BOOST_CHECK_EQUAL(t_const_int, test_lib::get_const_integer()); @@ -26,8 +26,10 @@ BOOST_AUTO_TEST_CASE(comparing_types_between_modules) BOOST_CHECK_NE(t_int, test_lib::get_const_integer()); - boost::type_index t_const_userdef = boost::type_id_with_cvr(); - boost::type_index t_userdef = boost::type_id(); + boost::typeind::type_index t_const_userdef + = boost::typeind::type_id_with_cvr(); + boost::typeind::type_index t_userdef + = boost::typeind::type_id(); BOOST_CHECK_EQUAL(t_userdef, test_lib::get_user_defined_class()); BOOST_CHECK_EQUAL(t_const_userdef, test_lib::get_const_user_defined_class()); diff --git a/test/type_index_test.cpp b/test/type_index_test.cpp index cd641e3..d1a1dec 100644 --- a/test/type_index_test.cpp +++ b/test/type_index_test.cpp @@ -207,8 +207,108 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test) BOOST_CHECK_EQUAL(type_id(), type_id()); BOOST_CHECK_EQUAL(type_id(), type_id()); +#ifndef BOOST_NO_RTTI + BOOST_CHECK(type_id() == typeid(my_namespace1::my_class)); + BOOST_CHECK(type_id() == typeid(my_namespace2::my_class)); + BOOST_CHECK(typeid(my_namespace1::my_class) == type_id()); + BOOST_CHECK(typeid(my_namespace2::my_class) == type_id()); +#endif + BOOST_CHECK_NE(type_id(), type_id()); BOOST_CHECK_NE( type_id().pretty_name().find("my_namespace1::my_class"), std::string::npos); } + + +#ifndef BOOST_NO_RTTI + +class A { public: virtual ~A(){} }; +class B: public A{}; +class C: public B {}; + +BOOST_AUTO_TEST_CASE(comparators_type_id_runtime) +{ + C c1; + B b1; + A* pc1 = &c1; + A& rc1 = c1; + A* pb1 = &b1; + A& rb1 = b1; + BOOST_CHECK(typeid(rc1) == typeid(*pc1)); + BOOST_CHECK(typeid(rb1) == typeid(*pb1)); + + BOOST_CHECK(typeid(rc1) != typeid(*pb1)); + BOOST_CHECK(typeid(rb1) != typeid(*pc1)); + + BOOST_CHECK(typeid(&rc1) == typeid(pb1)); + BOOST_CHECK(typeid(&rb1) == typeid(pc1)); + + BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(rc1), boost::typeind::type_id_runtime(*pc1)); + BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(rb1), boost::typeind::type_id_runtime(*pb1)); + + BOOST_CHECK_NE(boost::typeind::type_id_runtime(rc1), boost::typeind::type_id_runtime(*pb1)); + BOOST_CHECK_NE(boost::typeind::type_id_runtime(rb1), boost::typeind::type_id_runtime(*pc1)); + BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(&rc1), boost::typeind::type_id_runtime(pb1)); + BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(&rb1), boost::typeind::type_id_runtime(pc1)); + + BOOST_CHECK(boost::typeind::type_id_runtime(rc1) == typeid(*pc1)); + BOOST_CHECK(boost::typeind::type_id_runtime(rb1) == typeid(*pb1)); + + BOOST_CHECK(boost::typeind::type_id_runtime(rc1) != typeid(*pb1)); + BOOST_CHECK(boost::typeind::type_id_runtime(rb1) != typeid(*pc1)); + BOOST_CHECK(boost::typeind::type_id_runtime(&rc1) == typeid(pb1)); + BOOST_CHECK(boost::typeind::type_id_runtime(&rb1) == typeid(pc1)); +} + + +BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info) +{ + using namespace boost::typeind; + type_index t_int = type_id(); + + BOOST_CHECK(t_int == typeid(int)); + BOOST_CHECK(typeid(int) == t_int); + BOOST_CHECK(t_int <= typeid(int)); + BOOST_CHECK(typeid(int) <= t_int); + BOOST_CHECK(t_int >= typeid(int)); + BOOST_CHECK(typeid(int) >= t_int); + + type_index t_double = type_id(); + + BOOST_CHECK(t_double == typeid(double)); + BOOST_CHECK(typeid(double) == t_double); + BOOST_CHECK(t_double <= typeid(double)); + BOOST_CHECK(typeid(double) <= t_double); + BOOST_CHECK(t_double >= typeid(double)); + BOOST_CHECK(typeid(double) >= t_double); + + if (t_double < t_int) { + BOOST_CHECK(t_double < typeid(int)); + BOOST_CHECK(typeid(double) < t_int); + BOOST_CHECK(typeid(int) > t_double); + BOOST_CHECK(t_int > typeid(double)); + + + BOOST_CHECK(t_double <= typeid(int)); + BOOST_CHECK(typeid(double) <= t_int); + BOOST_CHECK(typeid(int) >= t_double); + BOOST_CHECK(t_int >= typeid(double)); + } else { + BOOST_CHECK(t_double > typeid(int)); + BOOST_CHECK(typeid(double) > t_int); + BOOST_CHECK(typeid(int) < t_double); + BOOST_CHECK(t_int < typeid(double)); + + + BOOST_CHECK(t_double >= typeid(int)); + BOOST_CHECK(typeid(double) >= t_int); + BOOST_CHECK(typeid(int) <= t_double); + BOOST_CHECK(t_int <= typeid(double)); + } + +} + +#endif // BOOST_NO_RTTI + + diff --git a/test/type_index_tests.ipp b/test/type_index_tests.ipp index 00e1619..d46d5c2 100644 --- a/test/type_index_tests.ipp +++ b/test/type_index_tests.ipp @@ -55,52 +55,7 @@ BOOST_AUTO_TEST_CASE(hash_code_type_id) #ifndef BOOST_NO_RTTI -BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info) -{ - using namespace boost; - type_index t_int = type_id(); - BOOST_CHECK(t_int == typeid(int)); - BOOST_CHECK(typeid(int) == t_int); - BOOST_CHECK(t_int <= typeid(int)); - BOOST_CHECK(typeid(int) <= t_int); - BOOST_CHECK(t_int >= typeid(int)); - BOOST_CHECK(typeid(int) >= t_int); - - type_index t_double = type_id(); - - BOOST_CHECK(t_double == typeid(double)); - BOOST_CHECK(typeid(double) == t_double); - BOOST_CHECK(t_double <= typeid(double)); - BOOST_CHECK(typeid(double) <= t_double); - BOOST_CHECK(t_double >= typeid(double)); - BOOST_CHECK(typeid(double) >= t_double); - - if (t_double < t_int) { - BOOST_CHECK(t_double < typeid(int)); - BOOST_CHECK(typeid(double) < t_int); - BOOST_CHECK(typeid(int) > t_double); - BOOST_CHECK(t_int > typeid(double)); - - - BOOST_CHECK(t_double <= typeid(int)); - BOOST_CHECK(typeid(double) <= t_int); - BOOST_CHECK(typeid(int) >= t_double); - BOOST_CHECK(t_int >= typeid(double)); - } else { - BOOST_CHECK(t_double > typeid(int)); - BOOST_CHECK(typeid(double) > t_int); - BOOST_CHECK(typeid(int) < t_double); - BOOST_CHECK(t_int < typeid(double)); - - - BOOST_CHECK(t_double >= typeid(int)); - BOOST_CHECK(typeid(double) >= t_int); - BOOST_CHECK(typeid(int) <= t_double); - BOOST_CHECK(t_int <= typeid(double)); - } - -} #endif // BOOST_NO_RTTI @@ -243,12 +198,6 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test) BOOST_CHECK_EQUAL(type_id(), type_id()); BOOST_CHECK_EQUAL(type_id(), type_id()); -#ifndef BOOST_NO_RTTI - BOOST_CHECK(type_id() == typeid(my_namespace1::my_class)); - BOOST_CHECK(type_id() == typeid(my_namespace2::my_class)); - BOOST_CHECK(typeid(my_namespace1::my_class) == type_id()); - BOOST_CHECK(typeid(my_namespace2::my_class) == type_id()); -#endif BOOST_CHECK_NE(type_id(), type_id()); BOOST_CHECK_NE( @@ -257,46 +206,6 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test) } -#ifndef BOOST_NO_RTTI - -class A { public: virtual ~A(){} }; -class B: public A{}; -class C: public B {}; - -BOOST_AUTO_TEST_CASE(comparators_type_id_rtti_only) -{ - C c1; - B b1; - A* pc1 = &c1; - A& rc1 = c1; - A* pb1 = &b1; - A& rb1 = b1; - BOOST_CHECK(typeid(rc1) == typeid(*pc1)); - BOOST_CHECK(typeid(rb1) == typeid(*pb1)); - - BOOST_CHECK(typeid(rc1) != typeid(*pb1)); - BOOST_CHECK(typeid(rb1) != typeid(*pc1)); - - BOOST_CHECK(typeid(&rc1) == typeid(pb1)); - BOOST_CHECK(typeid(&rb1) == typeid(pc1)); - - BOOST_CHECK_EQUAL(boost::type_id_rtti_only(rc1), boost::type_id_rtti_only(*pc1)); - BOOST_CHECK_EQUAL(boost::type_id_rtti_only(rb1), boost::type_id_rtti_only(*pb1)); - - BOOST_CHECK_NE(boost::type_id_rtti_only(rc1), boost::type_id_rtti_only(*pb1)); - BOOST_CHECK_NE(boost::type_id_rtti_only(rb1), boost::type_id_rtti_only(*pc1)); - BOOST_CHECK_EQUAL(boost::type_id_rtti_only(&rc1), boost::type_id_rtti_only(pb1)); - BOOST_CHECK_EQUAL(boost::type_id_rtti_only(&rb1), boost::type_id_rtti_only(pc1)); - - BOOST_CHECK(boost::type_id_rtti_only(rc1) == typeid(*pc1)); - BOOST_CHECK(boost::type_id_rtti_only(rb1) == typeid(*pb1)); - - BOOST_CHECK(boost::type_id_rtti_only(rc1) != typeid(*pb1)); - BOOST_CHECK(boost::type_id_rtti_only(rb1) != typeid(*pc1)); - BOOST_CHECK(boost::type_id_rtti_only(&rc1) == typeid(pb1)); - BOOST_CHECK(boost::type_id_rtti_only(&rb1) == typeid(pc1)); -} - -#endif // BOOST_NO_RTTI +