/******************************************************************************* * This file is part of the "https://github.com/blackmatov/meta.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md * Copyright (C) 2021-2024, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include #include namespace { const double pi_v{3.1415926536}; enum class color : unsigned { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF, }; struct ivec2 { int x{}; int y{}; explicit ivec2(int nv) : x{nv}, y{nv} {} ivec2(int nx, int ny) : x{nx}, y{ny} {} ivec2& add(const ivec2& other) noexcept { x += other.x; y += other.y; return *this; } static ivec2 iadd(const ivec2& l, const ivec2& r) noexcept { return {l.x + r.x, l.y + r.y}; } }; } TEST_CASE("meta/meta_utilities/hash/_") { namespace meta = meta_hpp; meta::enum_() .evalue_("red", color::red) .evalue_("green", color::green) .evalue_("blue", color::blue); meta::class_() .constructor_() .constructor_() .destructor_() .member_("x", &ivec2::x) .member_("y", &ivec2::y) .method_("add", &ivec2::add) .function_("iadd", &ivec2::iadd); } TEST_CASE("meta/meta_utilities/hash") { namespace meta = meta_hpp; const meta::class_type ivec2_type = meta::resolve_type(); const meta::constructor ivec2_ctor = ivec2_type.get_constructor_with(); const meta::destructor ivec2_dtor = ivec2_type.get_destructor(); const meta::function ivec2_function = ivec2_type.get_function("iadd"); const meta::argument ivec2_function_arg = ivec2_function.get_argument(0); const meta::member ivec2_member = ivec2_type.get_member("x"); const meta::method ivec2_method = ivec2_type.get_method("add"); const meta::enum_type color_type = meta::resolve_type(); const meta::evalue red_color = color_type.name_to_evalue("red"); const meta::scope local_scope = meta::local_scope_("local-scope") .variable_("pi_v", &pi_v); const meta::variable pi_variable = local_scope.get_variable("pi_v"); SUBCASE("index_family") { std::hash{}(ivec2_function_arg.get_index()); std::hash{}(ivec2_ctor.get_index()); std::hash{}(ivec2_dtor.get_index()); std::hash{}(red_color.get_index()); std::hash{}(ivec2_function.get_index()); std::hash{}(ivec2_member.get_index()); std::hash{}(ivec2_method.get_index()); std::hash{}(local_scope.get_index()); std::hash{}(pi_variable.get_index()); } SUBCASE("type_family") { std::hash{}(meta::resolve_type()); std::hash{}(meta::resolve_type()); std::hash{}(meta::resolve_type()); std::hash{}(ivec2_ctor.get_type()); std::hash{}(ivec2_dtor.get_type()); std::hash{}(red_color.get_type()); std::hash{}(ivec2_function.get_type()); std::hash{}(ivec2_member.get_type()); std::hash{}(ivec2_method.get_type()); std::hash{}(meta::resolve_type()); std::hash{}(meta::resolve_type()); std::hash{}(meta::resolve_type()); std::hash{}(meta::resolve_type()); std::hash{}(meta::resolve_type()); } }