mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
base type compare operators
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<shape>().id());
|
||||
CHECK(shape_info.type() == type_db::get<shape>());
|
||||
|
||||
CHECK_FALSE(shape_info.is_derived_from<shape>());
|
||||
CHECK_FALSE(shape_info.is_derived_from<rectangle>());
|
||||
@@ -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<rectangle>().id());
|
||||
CHECK(rectangle_info.type() == type_db::get<rectangle>());
|
||||
|
||||
CHECK(rectangle_info.is_derived_from<shape>());
|
||||
CHECK_FALSE(rectangle_info.is_derived_from<rectangle>());
|
||||
|
||||
@@ -58,8 +58,8 @@ TEST_CASE("features/infos/ctor") {
|
||||
const ctor_info ci3 = ivec2_info.get_ctor_by_args(std::vector<any_type>{});
|
||||
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<int>()});
|
||||
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<const ivec2&>()});
|
||||
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<int>()});
|
||||
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());
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ TEST_CASE("features/types/arithmetic") {
|
||||
|
||||
const arithmetic_type at = type_db::get<type>().as<arithmetic_type>();
|
||||
|
||||
CHECK(at.raw_type().id() == type_db::get<float>().id());
|
||||
CHECK(at.raw_type() == type_db::get<float>());
|
||||
CHECK(at.size() == sizeof(type));
|
||||
|
||||
CHECK(at.flags() == (
|
||||
@@ -66,7 +66,7 @@ TEST_CASE("features/types/arithmetic") {
|
||||
|
||||
const arithmetic_type at = type_db::get<type>().as<arithmetic_type>();
|
||||
|
||||
CHECK(at.raw_type().id() == type_db::get<unsigned>().id());
|
||||
CHECK(at.raw_type() == type_db::get<unsigned>());
|
||||
CHECK(at.size() == sizeof(type));
|
||||
|
||||
CHECK(at.flags() == (
|
||||
|
||||
@@ -21,7 +21,7 @@ TEST_CASE("features/types/array") {
|
||||
|
||||
const array_type at = type_db::get<type>().as<array_type>();
|
||||
|
||||
CHECK(at.data_type().id() == type_db::get<int>().id());
|
||||
CHECK(at.data_type() == type_db::get<int>());
|
||||
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<type>().as<array_type>();
|
||||
|
||||
CHECK(at.data_type().id() == type_db::get<unsigned[42]>().id());
|
||||
CHECK(at.data_type() == type_db::get<unsigned[42]>());
|
||||
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<type>().as<array_type>();
|
||||
|
||||
CHECK(at.data_type().id() == type_db::get<const int[21]>().id());
|
||||
CHECK(at.data_type() == type_db::get<const int[21]>());
|
||||
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<type>().as<array_type>();
|
||||
|
||||
CHECK(at.data_type().id() == type_db::get<const unsigned>().id());
|
||||
CHECK(at.data_type() == type_db::get<const unsigned>());
|
||||
CHECK(at.extent() == 42);
|
||||
|
||||
CHECK(at.flags() == (array_flags::is_bounded));
|
||||
|
||||
@@ -25,6 +25,6 @@ namespace
|
||||
TEST_CASE("features/types/base") {
|
||||
base_type bt{typename_arg<base>, typename_arg<derived>};
|
||||
|
||||
CHECK(bt.base_class_type().id() == type_db::get<base>().id());
|
||||
CHECK(bt.derived_class_type().id() == type_db::get<derived>().id());
|
||||
CHECK(bt.base_class_type() == type_db::get<base>());
|
||||
CHECK(bt.derived_class_type() == type_db::get<derived>());
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ TEST_CASE("features/types/class") {
|
||||
const class_type ct = type_db::get<type>().as<class_type>();
|
||||
|
||||
REQUIRE(ct.raw_type());
|
||||
CHECK(ct.raw_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(ct.raw_type() == type_db::get<ivec2>());
|
||||
CHECK(ct.size() == sizeof(type));
|
||||
|
||||
CHECK(ct.flags() == (
|
||||
|
||||
@@ -28,7 +28,7 @@ TEST_CASE("features/types/ctor") {
|
||||
SUBCASE("ivec2_void") {
|
||||
ctor_type ct{typename_arg<ivec2>, typename_arg<>};
|
||||
|
||||
CHECK(ct.class_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(ct.class_type() == type_db::get<ivec2>());
|
||||
CHECK(ct.argument_types().size() == 0);
|
||||
CHECK(ct.arity() == 0);
|
||||
|
||||
@@ -44,7 +44,7 @@ TEST_CASE("features/types/ctor") {
|
||||
ctor_type ct{typename_arg<ivec2>, typename_arg<int>};
|
||||
|
||||
CHECK(ct.arity() == 1);
|
||||
CHECK(ct.class_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(ct.class_type() == type_db::get<ivec2>());
|
||||
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<int>().id());
|
||||
CHECK(arg0 == type_db::get<int>());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -64,7 +64,7 @@ TEST_CASE("features/types/ctor") {
|
||||
SUBCASE("ivec2_int_int") {
|
||||
ctor_type ct{typename_arg<ivec2>, typename_arg<int, int>};
|
||||
|
||||
CHECK(ct.class_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(ct.class_type() == type_db::get<ivec2>());
|
||||
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<int>().id());
|
||||
CHECK(arg0 == type_db::get<int>());
|
||||
}
|
||||
|
||||
{
|
||||
REQUIRE(ct.argument_type(1));
|
||||
const any_type arg1 = ct.argument_type(1);
|
||||
CHECK(arg1.id() == type_db::get<int>().id());
|
||||
CHECK(arg1 == type_db::get<int>());
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -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<unsigned>().id());
|
||||
CHECK(et.underlying_type() == type_db::get<unsigned>());
|
||||
|
||||
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<ecolor>().id());
|
||||
CHECK(et.underlying_type().id() == type_db::get<unsigned>().id());
|
||||
CHECK(et.raw_type() == type_db::get<ecolor>());
|
||||
CHECK(et.underlying_type() == type_db::get<unsigned>());
|
||||
|
||||
CHECK(et.flags() == (enum_flags::is_const));
|
||||
CHECK(et.is_const());
|
||||
|
||||
@@ -32,7 +32,7 @@ TEST_CASE("features/types/function") {
|
||||
REQUIRE(type_db::get<type>().is<function_type>());
|
||||
|
||||
const function_type ft = type_db::get<type>().as<function_type>();
|
||||
CHECK(ft.return_type().id() == type_db::get<void>().id());
|
||||
CHECK(ft.return_type() == type_db::get<void>());
|
||||
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<ivec2>().id());
|
||||
CHECK(arg0 == type_db::get<ivec2>());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("features/types/function") {
|
||||
REQUIRE(type_db::get<type>().is<function_type>());
|
||||
|
||||
const function_type ft = type_db::get<type>().as<function_type>();
|
||||
CHECK(ft.return_type().id() == type_db::get<void>().id());
|
||||
CHECK(ft.return_type() == type_db::get<void>());
|
||||
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<ivec2&>().id());
|
||||
CHECK(arg0 == type_db::get<ivec2&>());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -82,7 +82,7 @@ TEST_CASE("features/types/function") {
|
||||
REQUIRE(type_db::get<type>().is<function_type>());
|
||||
|
||||
const function_type ft = type_db::get<type>().as<function_type>();
|
||||
CHECK(ft.return_type().id() == type_db::get<void>().id());
|
||||
CHECK(ft.return_type() == type_db::get<void>());
|
||||
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<const ivec2&>().id());
|
||||
CHECK(arg0 == type_db::get<const ivec2&>());
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -28,8 +28,8 @@ TEST_CASE("features/types/member") {
|
||||
REQUIRE(type_db::get<type>().is<member_type>());
|
||||
|
||||
const member_type mt = type_db::get<type>().as<member_type>();
|
||||
CHECK(mt.class_type().id() == type_db::get<clazz>().id());
|
||||
CHECK(mt.value_type().id() == type_db::get<int>().id());
|
||||
CHECK(mt.class_type() == type_db::get<clazz>());
|
||||
CHECK(mt.value_type() == type_db::get<int>());
|
||||
}
|
||||
|
||||
SUBCASE("clazz::const_int_member") {
|
||||
@@ -39,7 +39,7 @@ TEST_CASE("features/types/member") {
|
||||
REQUIRE(type_db::get<type>().is<member_type>());
|
||||
|
||||
const member_type mt = type_db::get<type>().as<member_type>();
|
||||
CHECK(mt.class_type().id() == type_db::get<clazz>().id());
|
||||
CHECK(mt.value_type().id() == type_db::get<const int>().id());
|
||||
CHECK(mt.class_type() == type_db::get<clazz>());
|
||||
CHECK(mt.value_type() == type_db::get<const int>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ TEST_CASE("features/types/method") {
|
||||
REQUIRE(type_db::get<type>().is<method_type>());
|
||||
|
||||
const method_type mt = type_db::get<type>().as<method_type>();
|
||||
CHECK(mt.class_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(mt.return_type().id() == type_db::get<int&>().id());
|
||||
CHECK(mt.class_type() == type_db::get<ivec2>());
|
||||
CHECK(mt.return_type() == type_db::get<int&>());
|
||||
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<std::size_t>().id());
|
||||
CHECK(arg0 == type_db::get<std::size_t>());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -68,8 +68,8 @@ TEST_CASE("features/types/method") {
|
||||
REQUIRE(type_db::get<type>().is<method_type>());
|
||||
|
||||
const method_type mt = type_db::get<type>().as<method_type>();
|
||||
CHECK(mt.class_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(mt.return_type().id() == type_db::get<int>().id());
|
||||
CHECK(mt.class_type() == type_db::get<ivec2>());
|
||||
CHECK(mt.return_type() == type_db::get<int>());
|
||||
CHECK(mt.argument_types().size() == 0);
|
||||
CHECK(mt.arity() == 0);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ TEST_CASE("features/types/pointer") {
|
||||
|
||||
const pointer_type pt = type_db::get<type>().as<pointer_type>();
|
||||
|
||||
CHECK(pt.data_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(pt.data_type() == type_db::get<ivec2>());
|
||||
|
||||
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<type>().as<pointer_type>();
|
||||
|
||||
CHECK(pt.data_type().id() == type_db::get<const ivec2>().id());
|
||||
CHECK(pt.data_type() == type_db::get<const ivec2>());
|
||||
|
||||
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<type>().as<pointer_type>();
|
||||
|
||||
CHECK(pt.data_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(pt.data_type() == type_db::get<ivec2>());
|
||||
|
||||
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<type>().as<pointer_type>();
|
||||
|
||||
CHECK(pt.data_type().id() == type_db::get<const ivec2>().id());
|
||||
CHECK(pt.data_type() == type_db::get<const ivec2>());
|
||||
|
||||
CHECK(pt.flags() == (pointer_flags::is_const));
|
||||
CHECK(pt.is_const());
|
||||
|
||||
@@ -27,7 +27,7 @@ TEST_CASE("features/types/reference") {
|
||||
|
||||
const reference_type rt = type_db::get<ivec2&>().as<reference_type>();
|
||||
|
||||
CHECK(rt.data_type().id() == type_db::get<ivec2>().id());
|
||||
CHECK(rt.data_type() == type_db::get<ivec2>());
|
||||
|
||||
CHECK(rt.flags() == (reference_flags::is_lvalue));
|
||||
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("features/types/reference") {
|
||||
|
||||
const reference_type rt = type_db::get<const ivec2&&>().as<reference_type>();
|
||||
|
||||
CHECK(rt.data_type().id() == type_db::get<const ivec2>().id());
|
||||
CHECK(rt.data_type() == type_db::get<const ivec2>());
|
||||
|
||||
CHECK(rt.flags() == (reference_flags::is_rvalue));
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST_CASE("features/types/void") {
|
||||
const void_type vt = type_db::get<type>().as<void_type>();
|
||||
|
||||
REQUIRE(vt.raw_type());
|
||||
CHECK(vt.raw_type().id() == type_db::get<void>().id());
|
||||
CHECK(vt.raw_type() == type_db::get<void>());
|
||||
|
||||
CHECK(vt.flags() == (void_flags::is_const));
|
||||
CHECK(vt.is_const());
|
||||
|
||||
Reference in New Issue
Block a user