Merge pull request #61 from BlackMATov/dev

Dev
This commit is contained in:
2023-03-14 04:17:22 +07:00
committed by GitHub
14 changed files with 228 additions and 82 deletions

26
ROADMAP.md Normal file
View File

@@ -0,0 +1,26 @@
# Roadmap
## Backlog
- instance mapper
- type conversions
- dynamic binds listener
- static binds listener
- dynamic type visitor
- type names by [nameof](https://github.com/Neargye/nameof)
- non-linear search of methods/functions/...
- register base types by `META_HPP_ENABLE_POLY_INFO`
- distinguish between function types and function pointer types
- add the library version to sources
- fix all includes to work with the library more flexible
- build and test on CI with additional flags like no-exception and no-rtti
- `try_invoke`/`is_invocable` should return error codes
- conan package config
- test and support shared libraries
- add `for_each_type` for specific kind of types
## Thoughts
- should `uvalue` dereference operators return `reference_wrapper`?
- `array_view`/`pointer_view` instead `unmap`/`operator[]`/`operator*`?
- can we add move-only uvalue analog to return move-only values?

View File

@@ -1798,10 +1798,10 @@ namespace meta_hpp
using metadata_map = std::map<std::string, uvalue, std::less<>>;
using typedef_map = std::map<std::string, any_type, std::less<>>;
using any_type_list = std::vector<any_type>;
using class_list = std::vector<class_type>;
using enum_list = std::vector<enum_type>;
using any_type_list = std::vector<any_type>;
using argument_list = std::vector<argument>;
using constructor_list = std::vector<constructor>;
using destructor_list = std::vector<destructor>;
@@ -2457,21 +2457,43 @@ namespace meta_hpp
public:
type_id() = default;
explicit type_id(std::uintptr_t id)
: id_{id} {}
[[nodiscard]] bool is_valid() const noexcept {
return data_ != nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
return is_valid();
}
void swap(type_id& other) noexcept {
std::swap(id_, other.id_);
std::swap(data_, other.data_);
}
[[nodiscard]] std::size_t get_hash() const noexcept {
return detail::hash_combiner{}(id_);
return data_ != nullptr ? detail::hash_combiner{}(data_) : 0;
}
[[nodiscard]] std::strong_ordering operator<=>(const type_id& other) const = default;
private:
std::uintptr_t id_{};
template < detail::type_family T >
friend class type_base;
explicit type_id(const detail::type_data_base* data)
: data_{data} {}
private:
const detail::type_data_base* data_{};
};
}
namespace std
{
template <>
struct hash<meta_hpp::type_id> {
size_t operator()(const meta_hpp::type_id& id) const noexcept {
return id.get_hash();
}
};
}
@@ -2505,8 +2527,7 @@ namespace meta_hpp
}
[[nodiscard]] id_type get_id() const noexcept {
// NOLINTNEXTLINE(*-reinterpret-cast)
return id_type{reinterpret_cast<std::uintptr_t>(data_)};
return id_type{data_};
}
[[nodiscard]] type_kind get_kind() const noexcept {
@@ -5597,8 +5618,14 @@ namespace meta_hpp
template < typename... Args >
uvalue invoke(const function& function, Args&&... args);
template < typename... Args >
uresult try_invoke(const function& function, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args >
uvalue invoke(Function function_ptr, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args >
uresult try_invoke(Function function_ptr, Args&&... args);
}
namespace meta_hpp
@@ -5606,8 +5633,14 @@ namespace meta_hpp
template < typename Instance >
uvalue invoke(const member& member, Instance&& instance);
template < typename Instance >
uresult try_invoke(const member& member, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance >
uvalue invoke(Member member_ptr, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance >
uresult try_invoke(Member member_ptr, Instance&& instance);
}
namespace meta_hpp
@@ -5615,53 +5648,59 @@ namespace meta_hpp
template < typename Instance, typename... Args >
uvalue invoke(const method& method, Instance&& instance, Args&&... args);
template < typename Instance, typename... Args >
uresult try_invoke(const method& method, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
uvalue invoke(Method method_ptr, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
uresult try_invoke(Method method_ptr, Instance&& instance, Args&&... args);
}
namespace meta_hpp
{
template < typename... Args >
bool is_invocable_with(const function& function);
bool is_invocable_with(const function& function) noexcept;
template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args);
bool is_invocable_with(const function& function, Args&&... args) noexcept;
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function);
bool is_invocable_with(Function) noexcept;
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function, Args&&... args);
bool is_invocable_with(Function, Args&&... args) noexcept;
}
namespace meta_hpp
{
template < typename Instance >
bool is_invocable_with(const member& member);
bool is_invocable_with(const member& member) noexcept;
template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance);
bool is_invocable_with(const member& member, Instance&& instance) noexcept;
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member);
bool is_invocable_with(Member) noexcept;
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member, Instance&& instance);
bool is_invocable_with(Member, Instance&& instance) noexcept;
}
namespace meta_hpp
{
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method);
bool is_invocable_with(const method& method) noexcept;
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args);
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) noexcept;
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method);
bool is_invocable_with(Method) noexcept;
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method, Instance&& instance, Args&&... args);
bool is_invocable_with(Method, Instance&& instance, Args&&... args) noexcept;
}
namespace meta_hpp::detail
@@ -6178,7 +6217,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < typename ArgTypeList >
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg> args) {
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg> args) noexcept {
if ( args.size() != type_list_arity_v<ArgTypeList> ) {
return false;
}
@@ -6189,7 +6228,7 @@ namespace meta_hpp::detail
}
template < typename ArgTypeList >
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg_base> args) {
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg_base> args) noexcept {
if ( args.size() != type_list_arity_v<ArgTypeList> ) {
return false;
}
@@ -6293,7 +6332,7 @@ namespace meta_hpp::detail
}
template < function_pointer_kind Function >
uerror raw_function_invoke_error(type_registry& registry, std::span<const uarg_base> args) {
uerror raw_function_invoke_error(type_registry& registry, std::span<const uarg_base> args) noexcept {
using ft = function_traits<Function>;
using argument_types = typename ft::argument_types;
@@ -6734,7 +6773,7 @@ namespace meta_hpp::detail
}
template < member_pointer_kind Member >
uerror raw_member_getter_error(type_registry& registry, const uinst_base& inst) {
uerror raw_member_getter_error(type_registry& registry, const uinst_base& inst) noexcept {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
@@ -6787,7 +6826,7 @@ namespace meta_hpp::detail
}
template < member_pointer_kind Member >
uerror raw_member_setter_error(type_registry& registry, const uinst_base& inst, const uarg_base& arg) {
uerror raw_member_setter_error(type_registry& registry, const uinst_base& inst, const uarg_base& arg) noexcept {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
@@ -7066,7 +7105,7 @@ namespace meta_hpp::detail
}
template < method_pointer_kind Method >
uerror raw_method_invoke_error(type_registry& registry, const uinst_base& inst, std::span<const uarg_base> args) {
uerror raw_method_invoke_error(type_registry& registry, const uinst_base& inst, std::span<const uarg_base> args) noexcept {
using mt = method_traits<Method>;
using qualified_type = typename mt::qualified_type;
using argument_types = typename mt::argument_types;
@@ -7322,17 +7361,17 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename... Args >
bool is_invocable_with(const function& function) {
bool is_invocable_with(const function& function) noexcept {
return function.is_invocable_with<Args...>();
}
template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args) {
bool is_invocable_with(const function& function, Args&&... args) noexcept {
return function.is_invocable_with(std::forward<Args>(args)...);
}
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function) {
bool is_invocable_with(Function) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, type_list<Args>{}}...};
@@ -7340,7 +7379,7 @@ namespace meta_hpp
}
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function, Args&&... args) {
bool is_invocable_with(Function, Args&&... args) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, std::forward<Args>(args)}...};
@@ -7351,17 +7390,17 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename Instance >
bool is_invocable_with(const member& member) {
bool is_invocable_with(const member& member) noexcept {
return member.is_gettable_with<Instance>();
}
template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance) {
bool is_invocable_with(const member& member, Instance&& instance) noexcept {
return member.is_gettable_with(std::forward<Instance>(instance));
}
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member) {
bool is_invocable_with(Member) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}};
@@ -7369,7 +7408,7 @@ namespace meta_hpp
}
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member, Instance&& instance) {
bool is_invocable_with(Member, Instance&& instance) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)};
@@ -7380,17 +7419,17 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method) {
bool is_invocable_with(const method& method) noexcept {
return method.is_invocable_with<Instance, Args...>();
}
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) {
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) noexcept {
return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...);
}
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method) {
bool is_invocable_with(Method) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}};
@@ -7399,7 +7438,7 @@ namespace meta_hpp
}
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method, Instance&& instance, Args&&... args) {
bool is_invocable_with(Method, Instance&& instance, Args&&... args) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)};
@@ -7537,7 +7576,7 @@ namespace meta_hpp::detail
}
template < class_kind Class, typename... Args >
uerror raw_constructor_create_error(type_registry& registry, std::span<const uarg_base> args) {
uerror raw_constructor_create_error(type_registry& registry, std::span<const uarg_base> args) noexcept {
using ct = constructor_traits<Class, Args...>;
using argument_types = typename ct::argument_types;
@@ -7733,7 +7772,7 @@ namespace meta_hpp::detail
}
template < class_kind Class >
uerror raw_destructor_destroy_error(type_registry& registry, const uarg_base& arg) {
uerror raw_destructor_destroy_error(type_registry& registry, const uarg_base& arg) noexcept {
using dt = destructor_traits<Class>;
using class_type = typename dt::class_type;
@@ -8007,7 +8046,7 @@ namespace meta_hpp::detail
}
template < pointer_kind Pointer >
uerror raw_variable_setter_error(type_registry& registry, const uarg_base& arg) {
uerror raw_variable_setter_error(type_registry& registry, const uarg_base& arg) noexcept {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;

View File

@@ -0,0 +1,42 @@
/*******************************************************************************
* 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-2023, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include <meta.hpp/meta_all.hpp>
#include <doctest/doctest.h>
TEST_CASE("meta/meta_types/type_id") {
namespace meta = meta_hpp;
SUBCASE("ctors/0") {
const meta::type_id id;
CHECK_FALSE(id);
CHECK_FALSE(id.is_valid());
}
SUBCASE("ctors/1") {
const meta::type_id int_id = meta::resolve_type<int>().get_id();
const meta::type_id float_id = meta::resolve_type<float>().get_id();
REQUIRE(int_id);
REQUIRE(float_id);
CHECK_FALSE(int_id == float_id);
CHECK(int_id != float_id);
CHECK((int_id < float_id || (float_id < int_id)));
}
SUBCASE("get_hash") {
const meta::type_id int_id = meta::resolve_type<int>().get_id();
const meta::type_id float_id = meta::resolve_type<float>().get_id();
REQUIRE(int_id);
REQUIRE(float_id);
CHECK(meta::type_id{}.get_hash() == 0);
CHECK_FALSE(int_id.get_hash() == float_id.get_hash());
CHECK(int_id.get_hash() == meta::resolve_type<int>().get_id().get_hash());
}
}

View File

@@ -222,10 +222,10 @@ namespace meta_hpp
using metadata_map = std::map<std::string, uvalue, std::less<>>;
using typedef_map = std::map<std::string, any_type, std::less<>>;
using any_type_list = std::vector<any_type>;
using class_list = std::vector<class_type>;
using enum_list = std::vector<enum_type>;
using any_type_list = std::vector<any_type>;
using argument_list = std::vector<argument>;
using constructor_list = std::vector<constructor>;
using destructor_list = std::vector<destructor>;

View File

@@ -341,7 +341,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < typename ArgTypeList >
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg> args) {
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg> args) noexcept {
if ( args.size() != type_list_arity_v<ArgTypeList> ) {
return false;
}
@@ -352,7 +352,7 @@ namespace meta_hpp::detail
}
template < typename ArgTypeList >
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg_base> args) {
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg_base> args) noexcept {
if ( args.size() != type_list_arity_v<ArgTypeList> ) {
return false;
}

View File

@@ -15,8 +15,14 @@ namespace meta_hpp
template < typename... Args >
uvalue invoke(const function& function, Args&&... args);
template < typename... Args >
uresult try_invoke(const function& function, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args >
uvalue invoke(Function function_ptr, Args&&... args);
template < detail::function_pointer_kind Function, typename... Args >
uresult try_invoke(Function function_ptr, Args&&... args);
}
namespace meta_hpp
@@ -24,8 +30,14 @@ namespace meta_hpp
template < typename Instance >
uvalue invoke(const member& member, Instance&& instance);
template < typename Instance >
uresult try_invoke(const member& member, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance >
uvalue invoke(Member member_ptr, Instance&& instance);
template < detail::member_pointer_kind Member, typename Instance >
uresult try_invoke(Member member_ptr, Instance&& instance);
}
namespace meta_hpp
@@ -33,51 +45,57 @@ namespace meta_hpp
template < typename Instance, typename... Args >
uvalue invoke(const method& method, Instance&& instance, Args&&... args);
template < typename Instance, typename... Args >
uresult try_invoke(const method& method, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
uvalue invoke(Method method_ptr, Instance&& instance, Args&&... args);
template < detail::method_pointer_kind Method, typename Instance, typename... Args >
uresult try_invoke(Method method_ptr, Instance&& instance, Args&&... args);
}
namespace meta_hpp
{
template < typename... Args >
bool is_invocable_with(const function& function);
bool is_invocable_with(const function& function) noexcept;
template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args);
bool is_invocable_with(const function& function, Args&&... args) noexcept;
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function);
bool is_invocable_with(Function) noexcept;
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function, Args&&... args);
bool is_invocable_with(Function, Args&&... args) noexcept;
}
namespace meta_hpp
{
template < typename Instance >
bool is_invocable_with(const member& member);
bool is_invocable_with(const member& member) noexcept;
template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance);
bool is_invocable_with(const member& member, Instance&& instance) noexcept;
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member);
bool is_invocable_with(Member) noexcept;
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member, Instance&& instance);
bool is_invocable_with(Member, Instance&& instance) noexcept;
}
namespace meta_hpp
{
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method);
bool is_invocable_with(const method& method) noexcept;
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args);
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) noexcept;
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method);
bool is_invocable_with(Method) noexcept;
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method, Instance&& instance, Args&&... args);
bool is_invocable_with(Method, Instance&& instance, Args&&... args) noexcept;
}

View File

@@ -134,17 +134,17 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename... Args >
bool is_invocable_with(const function& function) {
bool is_invocable_with(const function& function) noexcept {
return function.is_invocable_with<Args...>();
}
template < typename... Args >
bool is_invocable_with(const function& function, Args&&... args) {
bool is_invocable_with(const function& function, Args&&... args) noexcept {
return function.is_invocable_with(std::forward<Args>(args)...);
}
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function) {
bool is_invocable_with(Function) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, type_list<Args>{}}...};
@@ -152,7 +152,7 @@ namespace meta_hpp
}
template < typename... Args, detail::function_pointer_kind Function >
bool is_invocable_with(Function, Args&&... args) {
bool is_invocable_with(Function, Args&&... args) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{registry, std::forward<Args>(args)}...};
@@ -163,17 +163,17 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename Instance >
bool is_invocable_with(const member& member) {
bool is_invocable_with(const member& member) noexcept {
return member.is_gettable_with<Instance>();
}
template < typename Instance >
bool is_invocable_with(const member& member, Instance&& instance) {
bool is_invocable_with(const member& member, Instance&& instance) noexcept {
return member.is_gettable_with(std::forward<Instance>(instance));
}
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member) {
bool is_invocable_with(Member) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}};
@@ -181,7 +181,7 @@ namespace meta_hpp
}
template < typename Instance, detail::member_pointer_kind Member >
bool is_invocable_with(Member, Instance&& instance) {
bool is_invocable_with(Member, Instance&& instance) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)};
@@ -192,17 +192,17 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method) {
bool is_invocable_with(const method& method) noexcept {
return method.is_invocable_with<Instance, Args...>();
}
template < typename Instance, typename... Args >
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) {
bool is_invocable_with(const method& method, Instance&& instance, Args&&... args) noexcept {
return method.is_invocable_with(std::forward<Instance>(instance), std::forward<Args>(args)...);
}
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method) {
bool is_invocable_with(Method) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, type_list<Instance>{}};
@@ -211,7 +211,7 @@ namespace meta_hpp
}
template < typename Instance, typename... Args, detail::method_pointer_kind Method >
bool is_invocable_with(Method, Instance&& instance, Args&&... args) {
bool is_invocable_with(Method, Instance&& instance, Args&&... args) noexcept {
using namespace detail;
type_registry& registry{type_registry::instance()};
const uinst_base vinst{registry, std::forward<Instance>(instance)};

View File

@@ -80,7 +80,7 @@ namespace meta_hpp::detail
}
template < class_kind Class, typename... Args >
uerror raw_constructor_create_error(type_registry& registry, std::span<const uarg_base> args) {
uerror raw_constructor_create_error(type_registry& registry, std::span<const uarg_base> args) noexcept {
using ct = constructor_traits<Class, Args...>;
using argument_types = typename ct::argument_types;

View File

@@ -37,7 +37,7 @@ namespace meta_hpp::detail
}
template < class_kind Class >
uerror raw_destructor_destroy_error(type_registry& registry, const uarg_base& arg) {
uerror raw_destructor_destroy_error(type_registry& registry, const uarg_base& arg) noexcept {
using dt = destructor_traits<Class>;
using class_type = typename dt::class_type;

View File

@@ -64,7 +64,7 @@ namespace meta_hpp::detail
}
template < function_pointer_kind Function >
uerror raw_function_invoke_error(type_registry& registry, std::span<const uarg_base> args) {
uerror raw_function_invoke_error(type_registry& registry, std::span<const uarg_base> args) noexcept {
using ft = function_traits<Function>;
using argument_types = typename ft::argument_types;

View File

@@ -76,7 +76,7 @@ namespace meta_hpp::detail
}
template < member_pointer_kind Member >
uerror raw_member_getter_error(type_registry& registry, const uinst_base& inst) {
uerror raw_member_getter_error(type_registry& registry, const uinst_base& inst) noexcept {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
@@ -129,7 +129,7 @@ namespace meta_hpp::detail
}
template < member_pointer_kind Member >
uerror raw_member_setter_error(type_registry& registry, const uinst_base& inst, const uarg_base& arg) {
uerror raw_member_setter_error(type_registry& registry, const uinst_base& inst, const uarg_base& arg) noexcept {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;

View File

@@ -71,7 +71,7 @@ namespace meta_hpp::detail
}
template < method_pointer_kind Method >
uerror raw_method_invoke_error(type_registry& registry, const uinst_base& inst, std::span<const uarg_base> args) {
uerror raw_method_invoke_error(type_registry& registry, const uinst_base& inst, std::span<const uarg_base> args) noexcept {
using mt = method_traits<Method>;
using qualified_type = typename mt::qualified_type;
using argument_types = typename mt::argument_types;

View File

@@ -68,7 +68,7 @@ namespace meta_hpp::detail
}
template < pointer_kind Pointer >
uerror raw_variable_setter_error(type_registry& registry, const uarg_base& arg) {
uerror raw_variable_setter_error(type_registry& registry, const uarg_base& arg) noexcept {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;

View File

@@ -52,21 +52,43 @@ namespace meta_hpp
public:
type_id() = default;
explicit type_id(std::uintptr_t id)
: id_{id} {}
[[nodiscard]] bool is_valid() const noexcept {
return data_ != nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
return is_valid();
}
void swap(type_id& other) noexcept {
std::swap(id_, other.id_);
std::swap(data_, other.data_);
}
[[nodiscard]] std::size_t get_hash() const noexcept {
return detail::hash_combiner{}(id_);
return data_ != nullptr ? detail::hash_combiner{}(data_) : 0;
}
[[nodiscard]] std::strong_ordering operator<=>(const type_id& other) const = default;
private:
std::uintptr_t id_{};
template < detail::type_family T >
friend class type_base;
explicit type_id(const detail::type_data_base* data)
: data_{data} {}
private:
const detail::type_data_base* data_{};
};
}
namespace std
{
template <>
struct hash<meta_hpp::type_id> {
size_t operator()(const meta_hpp::type_id& id) const noexcept {
return id.get_hash();
}
};
}
@@ -100,8 +122,7 @@ namespace meta_hpp
}
[[nodiscard]] id_type get_id() const noexcept {
// NOLINTNEXTLINE(*-reinterpret-cast)
return id_type{reinterpret_cast<std::uintptr_t>(data_)};
return id_type{data_};
}
[[nodiscard]] type_kind get_kind() const noexcept {