From a9cfa7774404abfd1e10f5a57d340d6bce23f807 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 16 Aug 2021 19:23:08 +0700 Subject: [PATCH] base type compare operators --- headers/meta.hpp/meta_infos/class_info.hpp | 2 +- headers/meta.hpp/meta_types/_types_fwd.hpp | 44 +++++++++++++++++++ untests/features/infos/class_info_tests.cpp | 4 +- untests/features/infos/ctor_info_tests.cpp | 16 +++---- .../features/types/arithmetic_type_tests.cpp | 4 +- untests/features/types/array_type_tests.cpp | 8 ++-- untests/features/types/base_type_tests.cpp | 4 +- untests/features/types/class_type_tests.cpp | 2 +- untests/features/types/ctor_type_tests.cpp | 12 ++--- untests/features/types/enum_type_tests.cpp | 6 +-- .../features/types/function_type_tests.cpp | 12 ++--- untests/features/types/member_type_tests.cpp | 8 ++-- untests/features/types/method_type_tests.cpp | 10 ++--- untests/features/types/pointer_type_tests.cpp | 8 ++-- .../features/types/reference_type_tests.cpp | 4 +- untests/features/types/void_type_tests.cpp | 2 +- 16 files changed, 95 insertions(+), 51 deletions(-) diff --git a/headers/meta.hpp/meta_infos/class_info.hpp b/headers/meta.hpp/meta_infos/class_info.hpp index 7e861db..fc0ec79 100644 --- a/headers/meta.hpp/meta_infos/class_info.hpp +++ b/headers/meta.hpp/meta_infos/class_info.hpp @@ -125,7 +125,7 @@ namespace meta_hpp inline bool class_info::is_derived_from(any_type base) const noexcept { for ( auto&& id_info : state_->bases ) { - if ( base.id() == id_info.second.type().base_class_type().id() ) { + if ( base == id_info.second.type().base_class_type() ) { return true; } } diff --git a/headers/meta.hpp/meta_types/_types_fwd.hpp b/headers/meta.hpp/meta_types/_types_fwd.hpp index 316f868..39e8327 100644 --- a/headers/meta.hpp/meta_types/_types_fwd.hpp +++ b/headers/meta.hpp/meta_types/_types_fwd.hpp @@ -102,6 +102,20 @@ namespace meta_hpp private: type_id id_; }; + + // + + inline bool operator<(const type_base& l, const type_base& r) noexcept { + return l.id() < r.id(); + } + + inline bool operator==(const type_base& l, const type_base& r) noexcept { + return l.id() == r.id(); + } + + inline bool operator!=(const type_base& l, const type_base& r) noexcept { + return l.id() != r.id(); + } } namespace meta_hpp @@ -160,6 +174,8 @@ namespace meta_hpp const void_type*> type_; }; + // + inline bool operator<(const any_type& l, const any_type& r) noexcept { return l.id() < r.id(); } @@ -171,6 +187,34 @@ namespace meta_hpp inline bool operator!=(const any_type& l, const any_type& r) noexcept { return l.id() != r.id(); } + + // + + inline bool operator<(const type_base& l, const any_type& r) noexcept { + return l.id() < r.id(); + } + + inline bool operator==(const type_base& l, const any_type& r) noexcept { + return l.id() == r.id(); + } + + inline bool operator!=(const type_base& l, const any_type& r) noexcept { + return l.id() != r.id(); + } + + // + + inline bool operator<(const any_type& l, const type_base& r) noexcept { + return l.id() < r.id(); + } + + inline bool operator==(const any_type& l, const type_base& r) noexcept { + return l.id() == r.id(); + } + + inline bool operator!=(const any_type& l, const type_base& r) noexcept { + return l.id() != r.id(); + } } namespace std diff --git a/untests/features/infos/class_info_tests.cpp b/untests/features/infos/class_info_tests.cpp index b0a1a99..59bc299 100644 --- a/untests/features/infos/class_info_tests.cpp +++ b/untests/features/infos/class_info_tests.cpp @@ -76,7 +76,7 @@ TEST_CASE("features/infos/class") { REQUIRE(db.get_class_by_path("shape")); const class_info shape_info = db.get_class_by_path("shape"); CHECK(shape_info.name() == "shape"); - CHECK(shape_info.type().id() == type_db::get().id()); + CHECK(shape_info.type() == type_db::get()); CHECK_FALSE(shape_info.is_derived_from()); CHECK_FALSE(shape_info.is_derived_from()); @@ -86,7 +86,7 @@ TEST_CASE("features/infos/class") { REQUIRE(db.get_class_by_path("rectangle")); const class_info rectangle_info = db.get_class_by_path("rectangle"); CHECK(rectangle_info.name() == "rectangle"); - CHECK(rectangle_info.type().id() == type_db::get().id()); + CHECK(rectangle_info.type() == type_db::get()); CHECK(rectangle_info.is_derived_from()); CHECK_FALSE(rectangle_info.is_derived_from()); diff --git a/untests/features/infos/ctor_info_tests.cpp b/untests/features/infos/ctor_info_tests.cpp index eb0a78b..aa2d571 100644 --- a/untests/features/infos/ctor_info_tests.cpp +++ b/untests/features/infos/ctor_info_tests.cpp @@ -58,8 +58,8 @@ TEST_CASE("features/infos/ctor") { const ctor_info ci3 = ivec2_info.get_ctor_by_args(std::vector{}); REQUIRE(ci2); REQUIRE(ci3); - CHECK(ci.type().id() == ci2.type().id()); - CHECK(ci.type().id() == ci2.type().id()); + CHECK(ci.type() == ci2.type()); + CHECK(ci.type() == ci2.type()); } { @@ -93,8 +93,8 @@ TEST_CASE("features/infos/ctor") { type_db::get()}); REQUIRE(ci2); REQUIRE(ci3); - CHECK(ci.type().id() == ci2.type().id()); - CHECK(ci.type().id() == ci2.type().id()); + CHECK(ci.type() == ci2.type()); + CHECK(ci.type() == ci2.type()); } { @@ -128,8 +128,8 @@ TEST_CASE("features/infos/ctor") { type_db::get()}); REQUIRE(ci2); REQUIRE(ci3); - CHECK(ci.type().id() == ci2.type().id()); - CHECK(ci.type().id() == ci2.type().id()); + CHECK(ci.type() == ci2.type()); + CHECK(ci.type() == ci2.type()); } { @@ -172,8 +172,8 @@ TEST_CASE("features/infos/ctor") { type_db::get()}); REQUIRE(ci2); REQUIRE(ci3); - CHECK(ci.type().id() == ci2.type().id()); - CHECK(ci.type().id() == ci2.type().id()); + CHECK(ci.type() == ci2.type()); + CHECK(ci.type() == ci2.type()); } { diff --git a/untests/features/types/arithmetic_type_tests.cpp b/untests/features/types/arithmetic_type_tests.cpp index 5815e8e..c407be1 100644 --- a/untests/features/types/arithmetic_type_tests.cpp +++ b/untests/features/types/arithmetic_type_tests.cpp @@ -43,7 +43,7 @@ TEST_CASE("features/types/arithmetic") { const arithmetic_type at = type_db::get().as(); - CHECK(at.raw_type().id() == type_db::get().id()); + CHECK(at.raw_type() == type_db::get()); CHECK(at.size() == sizeof(type)); CHECK(at.flags() == ( @@ -66,7 +66,7 @@ TEST_CASE("features/types/arithmetic") { const arithmetic_type at = type_db::get().as(); - CHECK(at.raw_type().id() == type_db::get().id()); + CHECK(at.raw_type() == type_db::get()); CHECK(at.size() == sizeof(type)); CHECK(at.flags() == ( diff --git a/untests/features/types/array_type_tests.cpp b/untests/features/types/array_type_tests.cpp index c695cc2..b2f6169 100644 --- a/untests/features/types/array_type_tests.cpp +++ b/untests/features/types/array_type_tests.cpp @@ -21,7 +21,7 @@ TEST_CASE("features/types/array") { const array_type at = type_db::get().as(); - CHECK(at.data_type().id() == type_db::get().id()); + CHECK(at.data_type() == type_db::get()); CHECK(at.extent() == 0); CHECK(at.flags() == (array_flags::is_unbounded)); @@ -38,7 +38,7 @@ TEST_CASE("features/types/array") { const array_type at = type_db::get().as(); - CHECK(at.data_type().id() == type_db::get().id()); + CHECK(at.data_type() == type_db::get()); CHECK(at.extent() == 0); CHECK(at.flags() == (array_flags::is_unbounded)); @@ -55,7 +55,7 @@ TEST_CASE("features/types/array") { const array_type at = type_db::get().as(); - CHECK(at.data_type().id() == type_db::get().id()); + CHECK(at.data_type() == type_db::get()); CHECK(at.extent() == 42); CHECK(at.flags() == (array_flags::is_bounded)); @@ -72,7 +72,7 @@ TEST_CASE("features/types/array") { const array_type at = type_db::get().as(); - CHECK(at.data_type().id() == type_db::get().id()); + CHECK(at.data_type() == type_db::get()); CHECK(at.extent() == 42); CHECK(at.flags() == (array_flags::is_bounded)); diff --git a/untests/features/types/base_type_tests.cpp b/untests/features/types/base_type_tests.cpp index d7ae407..0a84731 100644 --- a/untests/features/types/base_type_tests.cpp +++ b/untests/features/types/base_type_tests.cpp @@ -25,6 +25,6 @@ namespace TEST_CASE("features/types/base") { base_type bt{typename_arg, typename_arg}; - CHECK(bt.base_class_type().id() == type_db::get().id()); - CHECK(bt.derived_class_type().id() == type_db::get().id()); + CHECK(bt.base_class_type() == type_db::get()); + CHECK(bt.derived_class_type() == type_db::get()); } diff --git a/untests/features/types/class_type_tests.cpp b/untests/features/types/class_type_tests.cpp index 00db749..bf4bbbc 100644 --- a/untests/features/types/class_type_tests.cpp +++ b/untests/features/types/class_type_tests.cpp @@ -127,7 +127,7 @@ TEST_CASE("features/types/class") { const class_type ct = type_db::get().as(); REQUIRE(ct.raw_type()); - CHECK(ct.raw_type().id() == type_db::get().id()); + CHECK(ct.raw_type() == type_db::get()); CHECK(ct.size() == sizeof(type)); CHECK(ct.flags() == ( diff --git a/untests/features/types/ctor_type_tests.cpp b/untests/features/types/ctor_type_tests.cpp index 3cdc84d..8245684 100644 --- a/untests/features/types/ctor_type_tests.cpp +++ b/untests/features/types/ctor_type_tests.cpp @@ -28,7 +28,7 @@ TEST_CASE("features/types/ctor") { SUBCASE("ivec2_void") { ctor_type ct{typename_arg, typename_arg<>}; - CHECK(ct.class_type().id() == type_db::get().id()); + CHECK(ct.class_type() == type_db::get()); CHECK(ct.argument_types().size() == 0); CHECK(ct.arity() == 0); @@ -44,7 +44,7 @@ TEST_CASE("features/types/ctor") { ctor_type ct{typename_arg, typename_arg}; CHECK(ct.arity() == 1); - CHECK(ct.class_type().id() == type_db::get().id()); + CHECK(ct.class_type() == type_db::get()); CHECK(ct.argument_types().size() == 1); CHECK(ct.flags() == (ctor_flags{})); @@ -53,7 +53,7 @@ TEST_CASE("features/types/ctor") { { REQUIRE(ct.argument_type(0)); const any_type arg0 = ct.argument_type(0); - CHECK(arg0.id() == type_db::get().id()); + CHECK(arg0 == type_db::get()); } { @@ -64,7 +64,7 @@ TEST_CASE("features/types/ctor") { SUBCASE("ivec2_int_int") { ctor_type ct{typename_arg, typename_arg}; - CHECK(ct.class_type().id() == type_db::get().id()); + CHECK(ct.class_type() == type_db::get()); CHECK(ct.argument_types().size() == 2); CHECK(ct.arity() == 2); @@ -74,13 +74,13 @@ TEST_CASE("features/types/ctor") { { REQUIRE(ct.argument_type(0)); const any_type arg0 = ct.argument_type(0); - CHECK(arg0.id() == type_db::get().id()); + CHECK(arg0 == type_db::get()); } { REQUIRE(ct.argument_type(1)); const any_type arg1 = ct.argument_type(1); - CHECK(arg1.id() == type_db::get().id()); + CHECK(arg1 == type_db::get()); } { diff --git a/untests/features/types/enum_type_tests.cpp b/untests/features/types/enum_type_tests.cpp index f96eb6f..03be3a7 100644 --- a/untests/features/types/enum_type_tests.cpp +++ b/untests/features/types/enum_type_tests.cpp @@ -32,7 +32,7 @@ TEST_CASE("features/types/enum") { CHECK(et.size() == sizeof(type)); CHECK_FALSE(et.raw_type()); - CHECK(et.underlying_type().id() == type_db::get().id()); + CHECK(et.underlying_type() == type_db::get()); CHECK(et.flags() == (enum_flags{})); CHECK_FALSE(et.is_const()); @@ -48,8 +48,8 @@ TEST_CASE("features/types/enum") { CHECK(et.size() == sizeof(type)); REQUIRE(et.raw_type()); - CHECK(et.raw_type().id() == type_db::get().id()); - CHECK(et.underlying_type().id() == type_db::get().id()); + CHECK(et.raw_type() == type_db::get()); + CHECK(et.underlying_type() == type_db::get()); CHECK(et.flags() == (enum_flags::is_const)); CHECK(et.is_const()); diff --git a/untests/features/types/function_type_tests.cpp b/untests/features/types/function_type_tests.cpp index 38632ab..fb3ac00 100644 --- a/untests/features/types/function_type_tests.cpp +++ b/untests/features/types/function_type_tests.cpp @@ -32,7 +32,7 @@ TEST_CASE("features/types/function") { REQUIRE(type_db::get().is()); const function_type ft = type_db::get().as(); - CHECK(ft.return_type().id() == type_db::get().id()); + CHECK(ft.return_type() == type_db::get()); CHECK(ft.argument_types().size() == 1); CHECK(ft.arity() == 1); @@ -42,7 +42,7 @@ TEST_CASE("features/types/function") { { REQUIRE(ft.argument_type(0)); const any_type arg0 = ft.argument_type(0); - CHECK(arg0.id() == type_db::get().id()); + CHECK(arg0 == type_db::get()); } { @@ -57,7 +57,7 @@ TEST_CASE("features/types/function") { REQUIRE(type_db::get().is()); const function_type ft = type_db::get().as(); - CHECK(ft.return_type().id() == type_db::get().id()); + CHECK(ft.return_type() == type_db::get()); CHECK(ft.argument_types().size() == 1); CHECK(ft.arity() == 1); @@ -67,7 +67,7 @@ TEST_CASE("features/types/function") { { REQUIRE(ft.argument_type(0)); const any_type arg0 = ft.argument_type(0); - CHECK(arg0.id() == type_db::get().id()); + CHECK(arg0 == type_db::get()); } { @@ -82,7 +82,7 @@ TEST_CASE("features/types/function") { REQUIRE(type_db::get().is()); const function_type ft = type_db::get().as(); - CHECK(ft.return_type().id() == type_db::get().id()); + CHECK(ft.return_type() == type_db::get()); CHECK(ft.argument_types().size() == 1); CHECK(ft.arity() == 1); @@ -92,7 +92,7 @@ TEST_CASE("features/types/function") { { REQUIRE(ft.argument_type(0)); const any_type arg0 = ft.argument_type(0); - CHECK(arg0.id() == type_db::get().id()); + CHECK(arg0 == type_db::get()); } { diff --git a/untests/features/types/member_type_tests.cpp b/untests/features/types/member_type_tests.cpp index 3115124..e085801 100644 --- a/untests/features/types/member_type_tests.cpp +++ b/untests/features/types/member_type_tests.cpp @@ -28,8 +28,8 @@ TEST_CASE("features/types/member") { REQUIRE(type_db::get().is()); const member_type mt = type_db::get().as(); - CHECK(mt.class_type().id() == type_db::get().id()); - CHECK(mt.value_type().id() == type_db::get().id()); + CHECK(mt.class_type() == type_db::get()); + CHECK(mt.value_type() == type_db::get()); } SUBCASE("clazz::const_int_member") { @@ -39,7 +39,7 @@ TEST_CASE("features/types/member") { REQUIRE(type_db::get().is()); const member_type mt = type_db::get().as(); - CHECK(mt.class_type().id() == type_db::get().id()); - CHECK(mt.value_type().id() == type_db::get().id()); + CHECK(mt.class_type() == type_db::get()); + CHECK(mt.value_type() == type_db::get()); } } diff --git a/untests/features/types/method_type_tests.cpp b/untests/features/types/method_type_tests.cpp index 084db51..334946d 100644 --- a/untests/features/types/method_type_tests.cpp +++ b/untests/features/types/method_type_tests.cpp @@ -40,8 +40,8 @@ TEST_CASE("features/types/method") { REQUIRE(type_db::get().is()); const method_type mt = type_db::get().as(); - CHECK(mt.class_type().id() == type_db::get().id()); - CHECK(mt.return_type().id() == type_db::get().id()); + CHECK(mt.class_type() == type_db::get()); + CHECK(mt.return_type() == type_db::get()); CHECK(mt.argument_types().size() == 1); CHECK(mt.arity() == 1); @@ -53,7 +53,7 @@ TEST_CASE("features/types/method") { { REQUIRE(mt.argument_type(0)); const any_type arg0 = mt.argument_type(0); - CHECK(arg0.id() == type_db::get().id()); + CHECK(arg0 == type_db::get()); } { @@ -68,8 +68,8 @@ TEST_CASE("features/types/method") { REQUIRE(type_db::get().is()); const method_type mt = type_db::get().as(); - CHECK(mt.class_type().id() == type_db::get().id()); - CHECK(mt.return_type().id() == type_db::get().id()); + CHECK(mt.class_type() == type_db::get()); + CHECK(mt.return_type() == type_db::get()); CHECK(mt.argument_types().size() == 0); CHECK(mt.arity() == 0); diff --git a/untests/features/types/pointer_type_tests.cpp b/untests/features/types/pointer_type_tests.cpp index 6fbc619..f267734 100644 --- a/untests/features/types/pointer_type_tests.cpp +++ b/untests/features/types/pointer_type_tests.cpp @@ -29,7 +29,7 @@ TEST_CASE("features/types/pointer") { const pointer_type pt = type_db::get().as(); - CHECK(pt.data_type().id() == type_db::get().id()); + CHECK(pt.data_type() == type_db::get()); CHECK(pt.flags() == (pointer_flags{})); CHECK_FALSE(pt.is_const()); @@ -43,7 +43,7 @@ TEST_CASE("features/types/pointer") { const pointer_type pt = type_db::get().as(); - CHECK(pt.data_type().id() == type_db::get().id()); + CHECK(pt.data_type() == type_db::get()); CHECK(pt.flags() == (pointer_flags{})); CHECK_FALSE(pt.is_const()); @@ -57,7 +57,7 @@ TEST_CASE("features/types/pointer") { const pointer_type pt = type_db::get().as(); - CHECK(pt.data_type().id() == type_db::get().id()); + CHECK(pt.data_type() == type_db::get()); CHECK(pt.flags() == (pointer_flags::is_const)); CHECK(pt.is_const()); @@ -71,7 +71,7 @@ TEST_CASE("features/types/pointer") { const pointer_type pt = type_db::get().as(); - CHECK(pt.data_type().id() == type_db::get().id()); + CHECK(pt.data_type() == type_db::get()); CHECK(pt.flags() == (pointer_flags::is_const)); CHECK(pt.is_const()); diff --git a/untests/features/types/reference_type_tests.cpp b/untests/features/types/reference_type_tests.cpp index be5bf72..0bacb4a 100644 --- a/untests/features/types/reference_type_tests.cpp +++ b/untests/features/types/reference_type_tests.cpp @@ -27,7 +27,7 @@ TEST_CASE("features/types/reference") { const reference_type rt = type_db::get().as(); - CHECK(rt.data_type().id() == type_db::get().id()); + CHECK(rt.data_type() == type_db::get()); CHECK(rt.flags() == (reference_flags::is_lvalue)); @@ -41,7 +41,7 @@ TEST_CASE("features/types/reference") { const reference_type rt = type_db::get().as(); - CHECK(rt.data_type().id() == type_db::get().id()); + CHECK(rt.data_type() == type_db::get()); CHECK(rt.flags() == (reference_flags::is_rvalue)); diff --git a/untests/features/types/void_type_tests.cpp b/untests/features/types/void_type_tests.cpp index a24fe5d..e53afb2 100644 --- a/untests/features/types/void_type_tests.cpp +++ b/untests/features/types/void_type_tests.cpp @@ -36,7 +36,7 @@ TEST_CASE("features/types/void") { const void_type vt = type_db::get().as(); REQUIRE(vt.raw_type()); - CHECK(vt.raw_type().id() == type_db::get().id()); + CHECK(vt.raw_type() == type_db::get()); CHECK(vt.flags() == (void_flags::is_const)); CHECK(vt.is_const());