From 5af1ad6b22721ff5435d5fa93ed257904da429c1 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 7 Jul 2023 02:57:16 +0700 Subject: [PATCH] distinguish between function types and function pointer types --- ROADMAP.md | 1 - .../manuals/meta_manuals/function_manual.cpp | 8 +- develop/singles/headers/meta.hpp/meta_all.hpp | 232 ++++++++++++------ .../untests/meta_issues/random_issue_3.cpp | 41 ++++ .../untests/meta_states/function_tests.cpp | 4 +- .../untests/meta_states/metadata_tests.cpp | 4 +- develop/untests/meta_types/any_type_tests.cpp | 6 +- .../meta_types/function_type_tests.cpp | 28 +-- headers/meta.hpp/meta_base/defer.hpp | 24 +- headers/meta.hpp/meta_base/type_kinds.hpp | 14 +- headers/meta.hpp/meta_binds.hpp | 4 +- headers/meta.hpp/meta_binds/function_bind.hpp | 2 +- .../meta.hpp/meta_detail/type_registry.hpp | 4 +- .../type_traits/function_traits.hpp | 6 +- .../meta_detail/value_utilities/uarg.hpp | 37 +-- .../meta_detail/value_utilities/utraits.hpp | 12 +- headers/meta.hpp/meta_states/argument.hpp | 7 +- headers/meta.hpp/meta_states/constructor.hpp | 11 +- headers/meta.hpp/meta_states/destructor.hpp | 8 +- headers/meta.hpp/meta_states/evalue.hpp | 8 +- headers/meta.hpp/meta_states/function.hpp | 17 +- headers/meta.hpp/meta_states/member.hpp | 8 +- headers/meta.hpp/meta_states/method.hpp | 11 +- headers/meta.hpp/meta_states/scope.hpp | 5 +- headers/meta.hpp/meta_states/variable.hpp | 8 +- headers/meta.hpp/meta_types.hpp | 26 +- headers/meta.hpp/meta_types/function_type.hpp | 2 +- headers/meta.hpp/meta_ucast.hpp | 16 +- headers/meta.hpp/meta_uvalue/uvalue.hpp | 2 + 29 files changed, 390 insertions(+), 166 deletions(-) create mode 100644 develop/untests/meta_issues/random_issue_3.cpp diff --git a/ROADMAP.md b/ROADMAP.md index 9456ccd..67218bb 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -5,7 +5,6 @@ - type conversions - 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 - `try_invoke`/`is_invocable` should return error codes diff --git a/develop/manuals/meta_manuals/function_manual.cpp b/develop/manuals/meta_manuals/function_manual.cpp index f669518..ac1a97e 100644 --- a/develop/manuals/meta_manuals/function_manual.cpp +++ b/develop/manuals/meta_manuals/function_manual.cpp @@ -23,11 +23,11 @@ namespace TEST_CASE("meta/meta_manuals/function/type") { namespace meta = meta_hpp; - // resolves a function type by pointer - const meta::function_type add_function_type = meta::resolve_type(&add); + // resolves a function type by reference + const meta::function_type add_function_type = meta::resolve_type(add); // also, it can be resolved by static function type declaration - CHECK(add_function_type == meta::resolve_type()); + CHECK(add_function_type == meta::resolve_type()); // checks a return value type CHECK(add_function_type.get_return_type() == meta::resolve_type()); @@ -55,7 +55,7 @@ TEST_CASE("meta/meta_manuals/function/usage") { CHECK(sub_function == math_scope.get_function_with("sub")); // checks a type of the found function - CHECK(sub_function.get_type() == meta::resolve_type()); + CHECK(sub_function.get_type() == meta::resolve_type()); // checks the ability to call the function with specific arguments CHECK(sub_function.is_invocable_with(60, 18)); diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index bd60bc9..6780a14 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -504,18 +504,30 @@ namespace meta_hpp::detail #ifdef __COUNTER__ # define META_HPP_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __COUNTER__) { ::meta_hpp::detail::make_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __COUNTER__) { \ + ::meta_hpp::detail::make_defer(__VA_ARGS__) \ + } # define META_HPP_ERROR_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __COUNTER__) { ::meta_hpp::detail::make_error_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __COUNTER__) { \ + ::meta_hpp::detail::make_error_defer(__VA_ARGS__) \ + } # define META_HPP_RETURN_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __COUNTER__) { ::meta_hpp::detail::make_return_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __COUNTER__) { \ + ::meta_hpp::detail::make_return_defer(__VA_ARGS__) \ + } #else # define META_HPP_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __LINE__) { ::meta_hpp::detail::make_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __LINE__) { \ + ::meta_hpp::detail::make_defer(__VA_ARGS__) \ + } # define META_HPP_ERROR_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __LINE__) { ::meta_hpp::detail::make_error_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __LINE__) { \ + ::meta_hpp::detail::make_error_defer(__VA_ARGS__) \ + } # define META_HPP_RETURN_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __LINE__) { ::meta_hpp::detail::make_return_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __LINE__) { \ + ::meta_hpp::detail::make_return_defer(__VA_ARGS__) \ + } #endif #if !defined(META_HPP_NO_EXCEPTIONS) @@ -1502,7 +1514,7 @@ namespace meta_hpp::detail concept enum_kind = std::is_enum_v; template < typename T > - concept function_pointer_kind = (std::is_pointer_v && std::is_function_v>); + concept function_kind = std::is_function_v; template < typename T > concept member_pointer_kind = std::is_member_object_pointer_v; @@ -1517,7 +1529,7 @@ namespace meta_hpp::detail concept number_kind = std::is_arithmetic_v; template < typename T > - concept pointer_kind = (std::is_pointer_v && !std::is_function_v>); + concept pointer_kind = std::is_pointer_v; template < typename T > concept reference_kind = std::is_reference_v; @@ -1529,7 +1541,13 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < typename T > - concept non_pointer_kind = (!pointer_kind); + concept non_pointer_kind = !std::is_pointer_v; + + template < typename T > + concept function_pointer_kind = std::is_pointer_v && std::is_function_v>; + + template < typename T > + concept non_function_pointer_kind = std::is_pointer_v && !std::is_function_v>; } namespace meta_hpp::detail @@ -1556,7 +1574,7 @@ namespace meta_hpp::detail if constexpr ( array_kind ) { return type_kind::array_; } if constexpr ( class_kind ) { return type_kind::class_; } if constexpr ( enum_kind ) { return type_kind::enum_; } - if constexpr ( function_pointer_kind ) { return type_kind::function_; } + if constexpr ( function_kind ) { return type_kind::function_; } if constexpr ( member_pointer_kind ) { return type_kind::member_; } if constexpr ( method_pointer_kind ) { return type_kind::method_; } if constexpr ( nullptr_kind ) { return type_kind::nullptr_; } @@ -2021,11 +2039,11 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < function_pointer_kind Function > + template < function_kind Function > struct function_traits; template < typename R, typename... Args > - struct function_traits { + struct function_traits { static constexpr std::size_t arity{sizeof...(Args)}; using return_type = R; @@ -2037,7 +2055,7 @@ namespace meta_hpp::detail }; template < typename R, typename... Args > - struct function_traits : function_traits { + struct function_traits : function_traits { [[nodiscard]] static constexpr function_bitflags make_flags() noexcept { return function_flags::is_noexcept; } @@ -2867,7 +2885,9 @@ namespace meta_hpp namespace meta_hpp::detail { struct type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const type_kind kind; + // NOLINTEND(*-avoid-const-or-ref-data-members) metadata_map metadata{}; @@ -2884,19 +2904,23 @@ namespace meta_hpp::detail }; struct array_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const array_bitflags flags; const std::size_t extent; const any_type data_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < array_kind Array > explicit array_type_data(type_list); }; struct class_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const class_bitflags flags; const std::size_t size; const std::size_t align; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) class_list base_classes; class_list derived_classes; @@ -2951,25 +2975,31 @@ namespace meta_hpp::detail }; struct constructor_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const constructor_bitflags flags; const class_type owner_type; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class, typename... Args > explicit constructor_type_data(type_list, type_list); }; struct destructor_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const destructor_bitflags flags; const class_type owner_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class > explicit destructor_type_data(type_list); }; struct enum_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const enum_bitflags flags; const number_type underlying_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) evalue_list evalues; @@ -2978,28 +3008,34 @@ namespace meta_hpp::detail }; struct function_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const function_bitflags flags; const any_type return_type; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) - template < function_pointer_kind Function > + template < function_kind Function > explicit function_type_data(type_list); }; struct member_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const member_bitflags flags; const class_type owner_type; const any_type value_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < member_pointer_kind Member > explicit member_type_data(type_list); }; struct method_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const method_bitflags flags; const class_type owner_type; const any_type return_type; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < method_pointer_kind Method > explicit method_type_data(type_list); @@ -3011,25 +3047,31 @@ namespace meta_hpp::detail }; struct number_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const number_bitflags flags; const std::size_t size; const std::size_t align; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < number_kind Number > explicit number_type_data(type_list); }; struct pointer_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const pointer_bitflags flags; const any_type data_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < pointer_kind Pointer > explicit pointer_type_data(type_list); }; struct reference_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const reference_bitflags flags; const any_type data_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < reference_kind Reference > explicit reference_type_data(type_list); @@ -4178,7 +4220,7 @@ namespace meta_hpp::detail if constexpr ( array_kind ) { return resolve_array_type(); } if constexpr ( class_kind ) { return resolve_class_type(); } if constexpr ( enum_kind ) { return resolve_enum_type(); } - if constexpr ( function_pointer_kind ) { return resolve_function_type(); } + if constexpr ( function_kind ) { return resolve_function_type(); } if constexpr ( member_pointer_kind ) { return resolve_member_type(); } if constexpr ( method_pointer_kind ) { return resolve_method_type(); } if constexpr ( nullptr_kind ) { return resolve_nullptr_type(); } @@ -4225,7 +4267,7 @@ namespace meta_hpp::detail return type; } - template < function_pointer_kind Function > + template < function_kind Function > [[nodiscard]] function_type resolve_function_type() { using function_t = std::remove_cv_t; static function_type type{ensure_type(type_list{})}; @@ -4716,7 +4758,7 @@ namespace meta_hpp namespace meta_hpp { - template < detail::function_pointer_kind Function > + template < detail::function_kind Function > class function_bind final : public type_bind_base { public: explicit function_bind(metadata_map metadata); @@ -4835,7 +4877,7 @@ namespace meta_hpp return enum_bind{std::move(metadata)}; } - template < detail::function_pointer_kind Function > + template < detail::function_kind Function > function_bind function_(metadata_map metadata = {}) { return function_bind{std::move(metadata)}; } @@ -5263,7 +5305,7 @@ namespace meta_hpp namespace meta_hpp { - template < detail::function_pointer_kind Function > + template < detail::function_kind Function > function_bind::function_bind(metadata_map metadata) : type_bind_base{resolve_type(), std::move(metadata)} {} } @@ -5713,12 +5755,12 @@ namespace meta_hpp::detail template < typename T, typename Tp = std::decay_t > concept arg_lvalue_ref_kind // = (non_uvalue_family) // - && (std::is_lvalue_reference_v); + &&(std::is_lvalue_reference_v); template < typename T, typename Tp = std::decay_t > concept arg_rvalue_ref_kind // = (non_uvalue_family) // - && (!std::is_reference_v || std::is_rvalue_reference_v); + &&(!std::is_reference_v || std::is_rvalue_reference_v); } namespace meta_hpp::detail @@ -5731,14 +5773,14 @@ namespace meta_hpp::detail template < typename T, typename Tp = std::decay_t > concept inst_class_lvalue_ref_kind // = (non_uvalue_family) // - && (std::is_lvalue_reference_v) // - && (std::is_class_v>>); + &&(std::is_lvalue_reference_v) // + &&(std::is_class_v>>); template < typename T, typename Tp = std::decay_t > concept inst_class_rvalue_ref_kind // = (non_uvalue_family) // - && (!std::is_reference_v || std::is_rvalue_reference_v) // - && (std::is_class_v>>); + &&(!std::is_reference_v || std::is_rvalue_reference_v) // + &&(std::is_class_v>>); } namespace meta_hpp::detail @@ -5963,10 +6005,11 @@ namespace meta_hpp::detail return raw_type_; } - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] bool can_cast_to(type_registry& registry) const noexcept; - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] bool can_cast_to(type_registry& registry) const noexcept; private: @@ -6005,10 +6048,11 @@ namespace meta_hpp::detail : uarg_base{registry, std::forward(v)} , data_{const_cast*>(std::addressof(v))} {} // NOLINT(*-const-cast) - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] decltype(auto) cast(type_registry& registry) const; - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] decltype(auto) cast(type_registry& registry) const; private: @@ -6018,7 +6062,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] bool uarg_base::can_cast_to(type_registry& registry) const noexcept { using to_raw_type = std::remove_cv_t; @@ -6064,7 +6108,8 @@ namespace meta_hpp::detail return false; } - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] bool uarg_base::can_cast_to(type_registry& registry) const noexcept { using to_raw_type_cv = std::remove_reference_t; using to_raw_type = std::remove_cv_t; @@ -6111,7 +6156,7 @@ namespace meta_hpp::detail } } - if constexpr ( non_pointer_kind && !std::is_reference_v ) { + if constexpr ( !std::is_reference_v ) { if ( is_a(to_type, from_type) && is_constructible_from_type(type_list{}) ) { return true; } @@ -6123,7 +6168,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] decltype(auto) uarg::cast(type_registry& registry) const { META_HPP_DEV_ASSERT(can_cast_to(registry) && "bad argument cast"); @@ -6165,7 +6210,8 @@ namespace meta_hpp::detail throw_exception(error_code::bad_argument_cast); } - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] decltype(auto) uarg::cast(type_registry& registry) const { META_HPP_DEV_ASSERT(can_cast_to(registry) && "bad argument cast"); @@ -6226,10 +6272,9 @@ namespace meta_hpp::detail if ( args.size() != type_list_arity_v ) { return false; } - return [ args, ®istry ](std::index_sequence) { + return [args, ®istry](std::index_sequence) { return (... && args[Is].can_cast_to>(registry)); - } - (std::make_index_sequence>()); + }(std::make_index_sequence>()); } template < typename ArgTypeList > @@ -6237,25 +6282,23 @@ namespace meta_hpp::detail if ( args.size() != type_list_arity_v ) { return false; } - return [ args, ®istry ](std::index_sequence) { + return [args, ®istry](std::index_sequence) { return (... && args[Is].can_cast_to>(registry)); - } - (std::make_index_sequence>()); + }(std::make_index_sequence>()); } template < typename ArgTypeList, typename F > auto unchecked_call_with_uargs(type_registry& registry, std::span args, F&& f) { META_HPP_DEV_ASSERT(args.size() == type_list_arity_v); - return [ args, ®istry, &f ](std::index_sequence) { + return [args, ®istry, &f](std::index_sequence) { return f(args[Is].cast>(registry)...); - } - (std::make_index_sequence>()); + }(std::make_index_sequence>()); } } namespace meta_hpp::detail { - template < function_pointer_kind Function > + template < function_kind Function > function_type_data::function_type_data(type_list) : type_data_base{type_kind::function_} , flags{function_traits::make_flags()} @@ -6290,7 +6333,7 @@ namespace meta_hpp::detail { template < function_policy_family Policy, function_pointer_kind Function > uvalue raw_function_invoke(type_registry& registry, Function function_ptr, std::span args) { - using ft = function_traits; + using ft = function_traits>; using return_type = typename ft::return_type; using argument_types = typename ft::argument_types; @@ -6338,7 +6381,7 @@ namespace meta_hpp::detail template < function_pointer_kind Function > uerror raw_function_invoke_error(type_registry& registry, std::span args) noexcept { - using ft = function_traits; + using ft = function_traits>; using argument_types = typename ft::argument_types; if ( args.size() != ft::arity ) { @@ -6371,7 +6414,7 @@ namespace meta_hpp::detail template < function_pointer_kind Function > argument_list make_function_arguments() { - using ft = function_traits; + using ft = function_traits>; using ft_argument_types = typename ft::argument_types; return [](std::index_sequence) { @@ -6380,8 +6423,7 @@ namespace meta_hpp::detail return argument{argument_state::make

(I, metadata_map{})}; }; return argument_list{make_argument(index_constant{})...}; - } - (std::make_index_sequence()); + }(std::make_index_sequence()); } } @@ -6394,10 +6436,16 @@ namespace meta_hpp::detail template < function_policy_family Policy, function_pointer_kind Function > function_state_ptr function_state::make(std::string name, Function function_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - function_state state{function_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + function_state state{ + function_index{registry.resolve_type>(), std::move(name)}, + std::move(metadata), + }; + state.invoke = make_function_invoke(registry, function_ptr); state.invoke_error = make_function_invoke_error(registry); state.arguments = make_function_arguments(); + return make_intrusive(std::move(state)); } } @@ -6899,11 +6947,17 @@ namespace meta_hpp::detail template < member_policy_family Policy, member_pointer_kind Member > member_state_ptr member_state::make(std::string name, Member member_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - member_state state{member_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + member_state state{ + member_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.getter = make_member_getter(registry, member_ptr); state.setter = make_member_setter(registry, member_ptr); state.getter_error = make_member_getter_error(registry); state.setter_error = make_member_setter_error(registry); + return make_intrusive(std::move(state)); } } @@ -7158,8 +7212,7 @@ namespace meta_hpp::detail return argument{argument_state::make

(I, metadata_map{})}; }; return argument_list{make_argument(index_constant{})...}; - } - (std::make_index_sequence()); + }(std::make_index_sequence()); } } @@ -7172,10 +7225,16 @@ namespace meta_hpp::detail template < method_policy_family Policy, method_pointer_kind Method > method_state_ptr method_state::make(std::string name, Method method_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - method_state state{method_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + method_state state{ + method_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.invoke = make_method_invoke(registry, method_ptr); state.invoke_error = make_method_invoke_error(registry); state.arguments = make_method_arguments(); + return make_intrusive(std::move(state)); } } @@ -7461,7 +7520,12 @@ namespace meta_hpp::detail template < typename Argument > inline argument_state_ptr argument_state::make(std::size_t position, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - argument_state state{argument_index{registry.resolve_type(), position}, std::move(metadata)}; + + argument_state state{ + argument_index{registry.resolve_type(), position}, + std::move(metadata), + }; + return make_intrusive(std::move(state)); } } @@ -7631,8 +7695,7 @@ namespace meta_hpp::detail return argument{argument_state::make

(I, metadata_map{})}; }; return argument_list{make_argument(index_constant{})...}; - } - (std::make_index_sequence()); + }(std::make_index_sequence()); } } @@ -7645,11 +7708,17 @@ namespace meta_hpp::detail template < constructor_policy_family Policy, class_kind Class, typename... Args > constructor_state_ptr constructor_state::make(metadata_map metadata) { type_registry& registry{type_registry::instance()}; - constructor_state state{constructor_index{registry.resolve_constructor_type()}, std::move(metadata)}; + + constructor_state state{ + constructor_index{registry.resolve_constructor_type()}, + std::move(metadata), + }; + state.create = make_constructor_create(registry); state.create_at = make_constructor_create_at(registry); state.create_error = make_constructor_create_error(registry); state.arguments = make_constructor_arguments(); + return make_intrusive(std::move(state)); } } @@ -7820,10 +7889,16 @@ namespace meta_hpp::detail template < class_kind Class > destructor_state_ptr destructor_state::make(metadata_map metadata) { type_registry& registry{type_registry::instance()}; - destructor_state state{destructor_index{registry.resolve_destructor_type()}, std::move(metadata)}; + + destructor_state state{ + destructor_index{registry.resolve_destructor_type()}, + std::move(metadata), + }; + state.destroy = make_destructor_destroy(registry); state.destroy_at = make_destructor_destroy_at(); state.destroy_error = make_destructor_destroy_error(registry); + return make_intrusive(std::move(state)); } } @@ -7950,9 +8025,15 @@ namespace meta_hpp::detail template < enum_kind Enum > evalue_state_ptr evalue_state::make(std::string name, Enum evalue, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - evalue_state state{evalue_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + evalue_state state{ + evalue_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.enum_value = uvalue{evalue}; state.underlying_value = uvalue{to_underlying(evalue)}; + return make_intrusive(std::move(state)); } } @@ -8101,10 +8182,16 @@ namespace meta_hpp::detail template < variable_policy_family Policy, pointer_kind Pointer > variable_state_ptr variable_state::make(std::string name, Pointer variable_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - variable_state state{variable_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + variable_state state{ + variable_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.getter = make_variable_getter(registry, variable_ptr); state.setter = make_variable_setter(registry, variable_ptr); state.setter_error = make_variable_setter_error(registry); + return make_intrusive(std::move(state)); } } @@ -8670,7 +8757,10 @@ namespace meta_hpp::detail , metadata{std::move(nmetadata)} {} inline scope_state_ptr scope_state::make(std::string name, metadata_map metadata) { - scope_state state{scope_index{std::move(name)}, std::move(metadata)}; + scope_state state{ + scope_index{std::move(name)}, + std::move(metadata), + }; return make_intrusive(std::move(state)); } } @@ -8985,11 +9075,11 @@ namespace meta_hpp::detail typename From, typename ToDT = std::remove_pointer_t, typename FromDT = std::remove_pointer_t > - concept pointer_ucast_kind // - = (std::is_pointer_v && std::is_class_v) // - && (std::is_pointer_v && (std::is_class_v || std::is_void_v)) // - && (!std::is_const_v || std::is_const_v) // - && (!std::is_volatile_v || std::is_volatile_v); // + concept pointer_ucast_kind // + = (std::is_pointer_v && std::is_class_v) // + &&(std::is_pointer_v && (std::is_class_v || std::is_void_v)) // + && (!std::is_const_v || std::is_const_v) // + &&(!std::is_volatile_v || std::is_volatile_v); // template < typename To, @@ -8998,9 +9088,9 @@ namespace meta_hpp::detail typename FromDT = std::remove_reference_t > concept lvalue_reference_ucast_kind // = (std::is_lvalue_reference_v && std::is_class_v) // - && (std::is_lvalue_reference_v && std::is_class_v) // - && (!std::is_const_v || std::is_const_v) // - && (!std::is_volatile_v || std::is_volatile_v); // + &&(std::is_lvalue_reference_v && std::is_class_v) // + &&(!std::is_const_v || std::is_const_v) // + &&(!std::is_volatile_v || std::is_volatile_v); // } namespace meta_hpp @@ -9227,6 +9317,7 @@ namespace meta_hpp::detail namespace meta_hpp { struct uvalue::vtable_t final { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const any_type type; void (*const move)(uvalue&& self, uvalue& to) noexcept; @@ -9236,6 +9327,7 @@ namespace meta_hpp uvalue (*const deref)(const storage_u& self); uvalue (*const index)(const storage_u& self, std::size_t i); uvalue (*const unmap)(const storage_u& self); + // NOLINTEND(*-avoid-const-or-ref-data-members) template < typename T > inline static constexpr bool in_internal_v = // diff --git a/develop/untests/meta_issues/random_issue_3.cpp b/develop/untests/meta_issues/random_issue_3.cpp new file mode 100644 index 0000000..d79cbf0 --- /dev/null +++ b/develop/untests/meta_issues/random_issue_3.cpp @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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 +#include + +namespace +{ + int int_func() { return 0; } +} + +TEST_CASE("meta/meta_issues/random/3") { + namespace meta = meta_hpp; + + static_assert(std::is_same_v()), meta_hpp::function_type>); + static_assert(std::is_same_v()), meta_hpp::pointer_type>); + static_assert(std::is_same_v()), meta_hpp::reference_type>); + + static_assert(std::is_same_v); + static_assert(std::is_same_v); + + CHECK(meta::resolve_type().get_kind() == meta::type_kind::function_); + CHECK(meta::resolve_type().get_kind() == meta::type_kind::pointer_); + CHECK(meta::resolve_type().get_kind() == meta::type_kind::reference_); + + CHECK(meta::resolve_type(int_func).get_kind() == meta::type_kind::function_); + CHECK(meta::resolve_type(&int_func).get_kind() == meta::type_kind::pointer_); + + CHECK(meta::resolve_type().get_data_type() == meta::resolve_type()); + CHECK(meta::resolve_type().get_data_type() == meta::resolve_type()); + + { + meta::uvalue v{&int_func}; + CHECK_FALSE(v.has_deref_op()); + CHECK(v.get_type() == meta::resolve_type()); + CHECK((v.as() == &int_func)); + } +} diff --git a/develop/untests/meta_states/function_tests.cpp b/develop/untests/meta_states/function_tests.cpp index bbc6297..0191020 100644 --- a/develop/untests/meta_states/function_tests.cpp +++ b/develop/untests/meta_states/function_tests.cpp @@ -70,7 +70,7 @@ TEST_CASE("meta/meta_states/function") { CHECK(func.get_index().get_type() == func.get_type()); CHECK(func.get_index().get_name() == "iadd"); - CHECK(func.get_type() == meta::resolve_type(&ivec2::iadd)); + CHECK(func.get_type() == meta::resolve_type(ivec2::iadd)); CHECK(func.get_name() == "iadd"); CHECK_FALSE(func.is_invocable_with<>()); @@ -99,7 +99,7 @@ TEST_CASE("meta/meta_states/function") { CHECK(func.get_index().get_type() == func.get_type()); CHECK(func.get_index().get_name() == "ilength2"); - CHECK(func.get_type() == meta::resolve_type(&ivec2::ilength2)); + CHECK(func.get_type() == meta::resolve_type(ivec2::ilength2)); CHECK(func.get_name() == "ilength2"); CHECK_FALSE(func.is_invocable_with<>()); diff --git a/develop/untests/meta_states/metadata_tests.cpp b/develop/untests/meta_states/metadata_tests.cpp index 292ce57..0d983e6 100644 --- a/develop/untests/meta_states/metadata_tests.cpp +++ b/develop/untests/meta_states/metadata_tests.cpp @@ -269,10 +269,10 @@ TEST_CASE("meta/meta_states/metadata/other") { } SUBCASE("function") { - meta::function_({ + meta::function_({ {"desc", "int->int"s} }); - CHECK(meta::resolve_type().get_metadata().at("desc").as() == "int->int"s); + CHECK(meta::resolve_type().get_metadata().at("desc").as() == "int->int"s); } SUBCASE("member") { diff --git a/develop/untests/meta_types/any_type_tests.cpp b/develop/untests/meta_types/any_type_tests.cpp index 1f851b0..6307d8e 100644 --- a/develop/untests/meta_types/any_type_tests.cpp +++ b/develop/untests/meta_types/any_type_tests.cpp @@ -118,11 +118,11 @@ TEST_CASE("meta/meta_types/any_type") { } SUBCASE("function") { - const meta::any_type& type = meta::resolve_type(&function_v); + const meta::any_type& type = meta::resolve_type(function_v); REQUIRE(type); - REQUIRE(type == meta::resolve_type()); - REQUIRE(type.get_id() == meta::resolve_type().get_id()); + REQUIRE(type == meta::resolve_type()); + REQUIRE(type.get_id() == meta::resolve_type().get_id()); CHECK(type.is_function()); CHECK(type.get_kind() == meta::type_kind::function_); diff --git a/develop/untests/meta_types/function_type_tests.cpp b/develop/untests/meta_types/function_type_tests.cpp index f445018..a0dc0a7 100644 --- a/develop/untests/meta_types/function_type_tests.cpp +++ b/develop/untests/meta_types/function_type_tests.cpp @@ -34,10 +34,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_copy") { - const meta::function_type type = meta::resolve_type(&arg_copy); + const meta::function_type type = meta::resolve_type(arg_copy); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_copy).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_copy).get_id()); CHECK(type.get_flags() == meta::function_flags{}); CHECK(type.get_arity() == 1); @@ -49,10 +49,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_ref_noexcept") { - const meta::function_type type = meta::resolve_type(&arg_ref_noexcept); + const meta::function_type type = meta::resolve_type(arg_ref_noexcept); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_ref_noexcept).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_ref_noexcept).get_id()); CHECK(type.get_flags() == meta::function_flags::is_noexcept); CHECK(type.get_argument_types() == meta::any_type_list{meta::resolve_type()}); @@ -61,10 +61,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_cref_noexcept") { - const meta::function_type type = meta::resolve_type(&arg_cref_noexcept); + const meta::function_type type = meta::resolve_type(arg_cref_noexcept); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_cref_noexcept).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_cref_noexcept).get_id()); CHECK(type.get_flags() == meta::function_flags::is_noexcept); CHECK(type.get_argument_types() == meta::any_type_list{meta::resolve_type()}); @@ -73,10 +73,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_bounded_arr") { - const meta::function_type type = meta::resolve_type(&arg_bounded_arr); + const meta::function_type type = meta::resolve_type(arg_bounded_arr); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_bounded_arr).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_bounded_arr).get_id()); CHECK(type.get_flags() == meta::function_flags{}); CHECK(type.get_argument_types() == meta::any_type_list{meta::resolve_type()}); @@ -85,10 +85,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_unbounded_arr") { - const meta::function_type type = meta::resolve_type(&arg_unbounded_arr); + const meta::function_type type = meta::resolve_type(arg_unbounded_arr); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_unbounded_arr).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_unbounded_arr).get_id()); CHECK(type.get_flags() == meta::function_flags{}); CHECK(type.get_argument_types() == meta::any_type_list{meta::resolve_type()}); @@ -97,10 +97,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_bounded_const_arr") { - const meta::function_type type = meta::resolve_type(&arg_bounded_const_arr); + const meta::function_type type = meta::resolve_type(arg_bounded_const_arr); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_bounded_const_arr).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_bounded_const_arr).get_id()); CHECK(type.get_flags() == meta::function_flags{}); CHECK(type.get_argument_types() == meta::any_type_list{meta::resolve_type()}); @@ -109,10 +109,10 @@ TEST_CASE("meta/meta_types/function_type") { } SUBCASE("arg_unbounded_const_arr") { - const meta::function_type type = meta::resolve_type(&arg_unbounded_const_arr); + const meta::function_type type = meta::resolve_type(arg_unbounded_const_arr); REQUIRE(type); - CHECK(type.get_id() == meta::resolve_type(&arg_unbounded_const_arr).get_id()); + CHECK(type.get_id() == meta::resolve_type(arg_unbounded_const_arr).get_id()); CHECK(type.get_flags() == meta::function_flags{}); CHECK(type.get_argument_types() == meta::any_type_list{meta::resolve_type()}); diff --git a/headers/meta.hpp/meta_base/defer.hpp b/headers/meta.hpp/meta_base/defer.hpp index 7450244..b69dfed 100644 --- a/headers/meta.hpp/meta_base/defer.hpp +++ b/headers/meta.hpp/meta_base/defer.hpp @@ -129,16 +129,28 @@ namespace meta_hpp::detail #ifdef __COUNTER__ # define META_HPP_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __COUNTER__) { ::meta_hpp::detail::make_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __COUNTER__) { \ + ::meta_hpp::detail::make_defer(__VA_ARGS__) \ + } # define META_HPP_ERROR_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __COUNTER__) { ::meta_hpp::detail::make_error_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __COUNTER__) { \ + ::meta_hpp::detail::make_error_defer(__VA_ARGS__) \ + } # define META_HPP_RETURN_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __COUNTER__) { ::meta_hpp::detail::make_return_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __COUNTER__) { \ + ::meta_hpp::detail::make_return_defer(__VA_ARGS__) \ + } #else # define META_HPP_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __LINE__) { ::meta_hpp::detail::make_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_defer_, __LINE__) { \ + ::meta_hpp::detail::make_defer(__VA_ARGS__) \ + } # define META_HPP_ERROR_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __LINE__) { ::meta_hpp::detail::make_error_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_error_defer_, __LINE__) { \ + ::meta_hpp::detail::make_error_defer(__VA_ARGS__) \ + } # define META_HPP_RETURN_DEFER(...) \ - auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __LINE__) { ::meta_hpp::detail::make_return_defer(__VA_ARGS__) } + auto META_HPP_PP_CAT(meta_hpp_generated_return_defer_, __LINE__) { \ + ::meta_hpp::detail::make_return_defer(__VA_ARGS__) \ + } #endif diff --git a/headers/meta.hpp/meta_base/type_kinds.hpp b/headers/meta.hpp/meta_base/type_kinds.hpp index 0ade348..02899f7 100644 --- a/headers/meta.hpp/meta_base/type_kinds.hpp +++ b/headers/meta.hpp/meta_base/type_kinds.hpp @@ -20,7 +20,7 @@ namespace meta_hpp::detail concept enum_kind = std::is_enum_v; template < typename T > - concept function_pointer_kind = (std::is_pointer_v && std::is_function_v>); + concept function_kind = std::is_function_v; template < typename T > concept member_pointer_kind = std::is_member_object_pointer_v; @@ -35,7 +35,7 @@ namespace meta_hpp::detail concept number_kind = std::is_arithmetic_v; template < typename T > - concept pointer_kind = (std::is_pointer_v && !std::is_function_v>); + concept pointer_kind = std::is_pointer_v; template < typename T > concept reference_kind = std::is_reference_v; @@ -47,7 +47,13 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < typename T > - concept non_pointer_kind = (!pointer_kind); + concept non_pointer_kind = !std::is_pointer_v; + + template < typename T > + concept function_pointer_kind = std::is_pointer_v && std::is_function_v>; + + template < typename T > + concept non_function_pointer_kind = std::is_pointer_v && !std::is_function_v>; } namespace meta_hpp::detail @@ -74,7 +80,7 @@ namespace meta_hpp::detail if constexpr ( array_kind ) { return type_kind::array_; } if constexpr ( class_kind ) { return type_kind::class_; } if constexpr ( enum_kind ) { return type_kind::enum_; } - if constexpr ( function_pointer_kind ) { return type_kind::function_; } + if constexpr ( function_kind ) { return type_kind::function_; } if constexpr ( member_pointer_kind ) { return type_kind::member_; } if constexpr ( method_pointer_kind ) { return type_kind::method_; } if constexpr ( nullptr_kind ) { return type_kind::nullptr_; } diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 5f2e50e..65d989c 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -235,7 +235,7 @@ namespace meta_hpp namespace meta_hpp { - template < detail::function_pointer_kind Function > + template < detail::function_kind Function > class function_bind final : public type_bind_base { public: explicit function_bind(metadata_map metadata); @@ -354,7 +354,7 @@ namespace meta_hpp return enum_bind{std::move(metadata)}; } - template < detail::function_pointer_kind Function > + template < detail::function_kind Function > function_bind function_(metadata_map metadata = {}) { return function_bind{std::move(metadata)}; } diff --git a/headers/meta.hpp/meta_binds/function_bind.hpp b/headers/meta.hpp/meta_binds/function_bind.hpp index 3388dad..e11dd6b 100644 --- a/headers/meta.hpp/meta_binds/function_bind.hpp +++ b/headers/meta.hpp/meta_binds/function_bind.hpp @@ -12,7 +12,7 @@ namespace meta_hpp { - template < detail::function_pointer_kind Function > + template < detail::function_kind Function > function_bind::function_bind(metadata_map metadata) : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_detail/type_registry.hpp b/headers/meta.hpp/meta_detail/type_registry.hpp index bfee60f..17fd94f 100644 --- a/headers/meta.hpp/meta_detail/type_registry.hpp +++ b/headers/meta.hpp/meta_detail/type_registry.hpp @@ -52,7 +52,7 @@ namespace meta_hpp::detail if constexpr ( array_kind ) { return resolve_array_type(); } if constexpr ( class_kind ) { return resolve_class_type(); } if constexpr ( enum_kind ) { return resolve_enum_type(); } - if constexpr ( function_pointer_kind ) { return resolve_function_type(); } + if constexpr ( function_kind ) { return resolve_function_type(); } if constexpr ( member_pointer_kind ) { return resolve_member_type(); } if constexpr ( method_pointer_kind ) { return resolve_method_type(); } if constexpr ( nullptr_kind ) { return resolve_nullptr_type(); } @@ -99,7 +99,7 @@ namespace meta_hpp::detail return type; } - template < function_pointer_kind Function > + template < function_kind Function > [[nodiscard]] function_type resolve_function_type() { using function_t = std::remove_cv_t; static function_type type{ensure_type(type_list{})}; diff --git a/headers/meta.hpp/meta_detail/type_traits/function_traits.hpp b/headers/meta.hpp/meta_detail/type_traits/function_traits.hpp index f7a52fc..4f12e52 100644 --- a/headers/meta.hpp/meta_detail/type_traits/function_traits.hpp +++ b/headers/meta.hpp/meta_detail/type_traits/function_traits.hpp @@ -20,11 +20,11 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < function_pointer_kind Function > + template < function_kind Function > struct function_traits; template < typename R, typename... Args > - struct function_traits { + struct function_traits { static constexpr std::size_t arity{sizeof...(Args)}; using return_type = R; @@ -36,7 +36,7 @@ namespace meta_hpp::detail }; template < typename R, typename... Args > - struct function_traits : function_traits { + struct function_traits : function_traits { [[nodiscard]] static constexpr function_bitflags make_flags() noexcept { return function_flags::is_noexcept; } diff --git a/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp b/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp index 7a15ec4..36f531a 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/uarg.hpp @@ -82,10 +82,11 @@ namespace meta_hpp::detail return raw_type_; } - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] bool can_cast_to(type_registry& registry) const noexcept; - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] bool can_cast_to(type_registry& registry) const noexcept; private: @@ -124,10 +125,11 @@ namespace meta_hpp::detail : uarg_base{registry, std::forward(v)} , data_{const_cast*>(std::addressof(v))} {} // NOLINT(*-const-cast) - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] decltype(auto) cast(type_registry& registry) const; - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] decltype(auto) cast(type_registry& registry) const; private: @@ -137,7 +139,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] bool uarg_base::can_cast_to(type_registry& registry) const noexcept { using to_raw_type = std::remove_cv_t; @@ -183,7 +185,8 @@ namespace meta_hpp::detail return false; } - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] bool uarg_base::can_cast_to(type_registry& registry) const noexcept { using to_raw_type_cv = std::remove_reference_t; using to_raw_type = std::remove_cv_t; @@ -230,7 +233,7 @@ namespace meta_hpp::detail } } - if constexpr ( non_pointer_kind && !std::is_reference_v ) { + if constexpr ( !std::is_reference_v ) { if ( is_a(to_type, from_type) && is_constructible_from_type(type_list{}) ) { return true; } @@ -242,7 +245,7 @@ namespace meta_hpp::detail namespace meta_hpp::detail { - template < pointer_kind To > + template < non_function_pointer_kind To > [[nodiscard]] decltype(auto) uarg::cast(type_registry& registry) const { META_HPP_DEV_ASSERT(can_cast_to(registry) && "bad argument cast"); @@ -284,7 +287,8 @@ namespace meta_hpp::detail throw_exception(error_code::bad_argument_cast); } - template < non_pointer_kind To > + template < typename To > + requires(!non_function_pointer_kind) [[nodiscard]] decltype(auto) uarg::cast(type_registry& registry) const { META_HPP_DEV_ASSERT(can_cast_to(registry) && "bad argument cast"); @@ -345,10 +349,9 @@ namespace meta_hpp::detail if ( args.size() != type_list_arity_v ) { return false; } - return [ args, ®istry ](std::index_sequence) { + return [args, ®istry](std::index_sequence) { return (... && args[Is].can_cast_to>(registry)); - } - (std::make_index_sequence>()); + }(std::make_index_sequence>()); } template < typename ArgTypeList > @@ -356,18 +359,16 @@ namespace meta_hpp::detail if ( args.size() != type_list_arity_v ) { return false; } - return [ args, ®istry ](std::index_sequence) { + return [args, ®istry](std::index_sequence) { return (... && args[Is].can_cast_to>(registry)); - } - (std::make_index_sequence>()); + }(std::make_index_sequence>()); } template < typename ArgTypeList, typename F > auto unchecked_call_with_uargs(type_registry& registry, std::span args, F&& f) { META_HPP_DEV_ASSERT(args.size() == type_list_arity_v); - return [ args, ®istry, &f ](std::index_sequence) { + return [args, ®istry, &f](std::index_sequence) { return f(args[Is].cast>(registry)...); - } - (std::make_index_sequence>()); + }(std::make_index_sequence>()); } } diff --git a/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp b/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp index 68c78d0..42ff8ab 100644 --- a/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp +++ b/headers/meta.hpp/meta_detail/value_utilities/utraits.hpp @@ -14,12 +14,12 @@ namespace meta_hpp::detail template < typename T, typename Tp = std::decay_t > concept arg_lvalue_ref_kind // = (non_uvalue_family) // - && (std::is_lvalue_reference_v); + &&(std::is_lvalue_reference_v); template < typename T, typename Tp = std::decay_t > concept arg_rvalue_ref_kind // = (non_uvalue_family) // - && (!std::is_reference_v || std::is_rvalue_reference_v); + &&(!std::is_reference_v || std::is_rvalue_reference_v); } namespace meta_hpp::detail @@ -32,14 +32,14 @@ namespace meta_hpp::detail template < typename T, typename Tp = std::decay_t > concept inst_class_lvalue_ref_kind // = (non_uvalue_family) // - && (std::is_lvalue_reference_v) // - && (std::is_class_v>>); + &&(std::is_lvalue_reference_v) // + &&(std::is_class_v>>); template < typename T, typename Tp = std::decay_t > concept inst_class_rvalue_ref_kind // = (non_uvalue_family) // - && (!std::is_reference_v || std::is_rvalue_reference_v) // - && (std::is_class_v>>); + &&(!std::is_reference_v || std::is_rvalue_reference_v) // + &&(std::is_class_v>>); } namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_states/argument.hpp b/headers/meta.hpp/meta_states/argument.hpp index ebe0921..38b25d6 100644 --- a/headers/meta.hpp/meta_states/argument.hpp +++ b/headers/meta.hpp/meta_states/argument.hpp @@ -20,7 +20,12 @@ namespace meta_hpp::detail template < typename Argument > inline argument_state_ptr argument_state::make(std::size_t position, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - argument_state state{argument_index{registry.resolve_type(), position}, std::move(metadata)}; + + argument_state state{ + argument_index{registry.resolve_type(), position}, + std::move(metadata), + }; + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 28c8aff..a947a92 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -130,8 +130,7 @@ namespace meta_hpp::detail return argument{argument_state::make

(I, metadata_map{})}; }; return argument_list{make_argument(index_constant{})...}; - } - (std::make_index_sequence()); + }(std::make_index_sequence()); } } @@ -144,11 +143,17 @@ namespace meta_hpp::detail template < constructor_policy_family Policy, class_kind Class, typename... Args > constructor_state_ptr constructor_state::make(metadata_map metadata) { type_registry& registry{type_registry::instance()}; - constructor_state state{constructor_index{registry.resolve_constructor_type()}, std::move(metadata)}; + + constructor_state state{ + constructor_index{registry.resolve_constructor_type()}, + std::move(metadata), + }; + state.create = make_constructor_create(registry); state.create_at = make_constructor_create_at(registry); state.create_error = make_constructor_create_error(registry); state.arguments = make_constructor_arguments(); + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/destructor.hpp b/headers/meta.hpp/meta_states/destructor.hpp index 57dd59c..bd82df4 100644 --- a/headers/meta.hpp/meta_states/destructor.hpp +++ b/headers/meta.hpp/meta_states/destructor.hpp @@ -80,10 +80,16 @@ namespace meta_hpp::detail template < class_kind Class > destructor_state_ptr destructor_state::make(metadata_map metadata) { type_registry& registry{type_registry::instance()}; - destructor_state state{destructor_index{registry.resolve_destructor_type()}, std::move(metadata)}; + + destructor_state state{ + destructor_index{registry.resolve_destructor_type()}, + std::move(metadata), + }; + state.destroy = make_destructor_destroy(registry); state.destroy_at = make_destructor_destroy_at(); state.destroy_error = make_destructor_destroy_error(registry); + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/evalue.hpp b/headers/meta.hpp/meta_states/evalue.hpp index ecdf40d..37f6299 100644 --- a/headers/meta.hpp/meta_states/evalue.hpp +++ b/headers/meta.hpp/meta_states/evalue.hpp @@ -21,9 +21,15 @@ namespace meta_hpp::detail template < enum_kind Enum > evalue_state_ptr evalue_state::make(std::string name, Enum evalue, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - evalue_state state{evalue_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + evalue_state state{ + evalue_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.enum_value = uvalue{evalue}; state.underlying_value = uvalue{to_underlying(evalue)}; + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 05ef491..94748fa 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -17,7 +17,7 @@ namespace meta_hpp::detail { template < function_policy_family Policy, function_pointer_kind Function > uvalue raw_function_invoke(type_registry& registry, Function function_ptr, std::span args) { - using ft = function_traits; + using ft = function_traits>; using return_type = typename ft::return_type; using argument_types = typename ft::argument_types; @@ -65,7 +65,7 @@ namespace meta_hpp::detail template < function_pointer_kind Function > uerror raw_function_invoke_error(type_registry& registry, std::span args) noexcept { - using ft = function_traits; + using ft = function_traits>; using argument_types = typename ft::argument_types; if ( args.size() != ft::arity ) { @@ -98,7 +98,7 @@ namespace meta_hpp::detail template < function_pointer_kind Function > argument_list make_function_arguments() { - using ft = function_traits; + using ft = function_traits>; using ft_argument_types = typename ft::argument_types; return [](std::index_sequence) { @@ -107,8 +107,7 @@ namespace meta_hpp::detail return argument{argument_state::make

(I, metadata_map{})}; }; return argument_list{make_argument(index_constant{})...}; - } - (std::make_index_sequence()); + }(std::make_index_sequence()); } } @@ -121,10 +120,16 @@ namespace meta_hpp::detail template < function_policy_family Policy, function_pointer_kind Function > function_state_ptr function_state::make(std::string name, Function function_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - function_state state{function_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + function_state state{ + function_index{registry.resolve_type>(), std::move(name)}, + std::move(metadata), + }; + state.invoke = make_function_invoke(registry, function_ptr); state.invoke_error = make_function_invoke_error(registry); state.arguments = make_function_arguments(); + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index b7c63f5..c22eda7 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -197,11 +197,17 @@ namespace meta_hpp::detail template < member_policy_family Policy, member_pointer_kind Member > member_state_ptr member_state::make(std::string name, Member member_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - member_state state{member_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + member_state state{ + member_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.getter = make_member_getter(registry, member_ptr); state.setter = make_member_setter(registry, member_ptr); state.getter_error = make_member_getter_error(registry); state.setter_error = make_member_setter_error(registry); + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index f212119..5076057 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -119,8 +119,7 @@ namespace meta_hpp::detail return argument{argument_state::make

(I, metadata_map{})}; }; return argument_list{make_argument(index_constant{})...}; - } - (std::make_index_sequence()); + }(std::make_index_sequence()); } } @@ -133,10 +132,16 @@ namespace meta_hpp::detail template < method_policy_family Policy, method_pointer_kind Method > method_state_ptr method_state::make(std::string name, Method method_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - method_state state{method_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + method_state state{ + method_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.invoke = make_method_invoke(registry, method_ptr); state.invoke_error = make_method_invoke_error(registry); state.arguments = make_method_arguments(); + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index d80f262..c3f3df4 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -23,7 +23,10 @@ namespace meta_hpp::detail , metadata{std::move(nmetadata)} {} inline scope_state_ptr scope_state::make(std::string name, metadata_map metadata) { - scope_state state{scope_index{std::move(name)}, std::move(metadata)}; + scope_state state{ + scope_index{std::move(name)}, + std::move(metadata), + }; return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 7ced140..16d23b3 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -118,10 +118,16 @@ namespace meta_hpp::detail template < variable_policy_family Policy, pointer_kind Pointer > variable_state_ptr variable_state::make(std::string name, Pointer variable_ptr, metadata_map metadata) { type_registry& registry{type_registry::instance()}; - variable_state state{variable_index{registry.resolve_type(), std::move(name)}, std::move(metadata)}; + + variable_state state{ + variable_index{registry.resolve_type(), std::move(name)}, + std::move(metadata), + }; + state.getter = make_variable_getter(registry, variable_ptr); state.setter = make_variable_setter(registry, variable_ptr); state.setter_error = make_variable_setter_error(registry); + return make_intrusive(std::move(state)); } } diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index 55bb8ad..ba63445 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -462,7 +462,9 @@ namespace meta_hpp namespace meta_hpp::detail { struct type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const type_kind kind; + // NOLINTEND(*-avoid-const-or-ref-data-members) metadata_map metadata{}; @@ -479,19 +481,23 @@ namespace meta_hpp::detail }; struct array_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const array_bitflags flags; const std::size_t extent; const any_type data_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < array_kind Array > explicit array_type_data(type_list); }; struct class_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const class_bitflags flags; const std::size_t size; const std::size_t align; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) class_list base_classes; class_list derived_classes; @@ -546,25 +552,31 @@ namespace meta_hpp::detail }; struct constructor_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const constructor_bitflags flags; const class_type owner_type; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class, typename... Args > explicit constructor_type_data(type_list, type_list); }; struct destructor_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const destructor_bitflags flags; const class_type owner_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < class_kind Class > explicit destructor_type_data(type_list); }; struct enum_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const enum_bitflags flags; const number_type underlying_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) evalue_list evalues; @@ -573,28 +585,34 @@ namespace meta_hpp::detail }; struct function_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const function_bitflags flags; const any_type return_type; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) - template < function_pointer_kind Function > + template < function_kind Function > explicit function_type_data(type_list); }; struct member_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const member_bitflags flags; const class_type owner_type; const any_type value_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < member_pointer_kind Member > explicit member_type_data(type_list); }; struct method_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const method_bitflags flags; const class_type owner_type; const any_type return_type; const any_type_list argument_types; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < method_pointer_kind Method > explicit method_type_data(type_list); @@ -606,25 +624,31 @@ namespace meta_hpp::detail }; struct number_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const number_bitflags flags; const std::size_t size; const std::size_t align; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < number_kind Number > explicit number_type_data(type_list); }; struct pointer_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const pointer_bitflags flags; const any_type data_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < pointer_kind Pointer > explicit pointer_type_data(type_list); }; struct reference_type_data final : type_data_base { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const reference_bitflags flags; const any_type data_type; + // NOLINTEND(*-avoid-const-or-ref-data-members) template < reference_kind Reference > explicit reference_type_data(type_list); diff --git a/headers/meta.hpp/meta_types/function_type.hpp b/headers/meta.hpp/meta_types/function_type.hpp index ab928c5..362b64b 100644 --- a/headers/meta.hpp/meta_types/function_type.hpp +++ b/headers/meta.hpp/meta_types/function_type.hpp @@ -14,7 +14,7 @@ namespace meta_hpp::detail { - template < function_pointer_kind Function > + template < function_kind Function > function_type_data::function_type_data(type_list) : type_data_base{type_kind::function_} , flags{function_traits::make_flags()} diff --git a/headers/meta.hpp/meta_ucast.hpp b/headers/meta.hpp/meta_ucast.hpp index 35dd5fc..9f962b3 100644 --- a/headers/meta.hpp/meta_ucast.hpp +++ b/headers/meta.hpp/meta_ucast.hpp @@ -15,11 +15,11 @@ namespace meta_hpp::detail typename From, typename ToDT = std::remove_pointer_t, typename FromDT = std::remove_pointer_t > - concept pointer_ucast_kind // - = (std::is_pointer_v && std::is_class_v) // - && (std::is_pointer_v && (std::is_class_v || std::is_void_v)) // - && (!std::is_const_v || std::is_const_v) // - && (!std::is_volatile_v || std::is_volatile_v); // + concept pointer_ucast_kind // + = (std::is_pointer_v && std::is_class_v) // + &&(std::is_pointer_v && (std::is_class_v || std::is_void_v)) // + && (!std::is_const_v || std::is_const_v) // + &&(!std::is_volatile_v || std::is_volatile_v); // template < typename To, @@ -28,9 +28,9 @@ namespace meta_hpp::detail typename FromDT = std::remove_reference_t > concept lvalue_reference_ucast_kind // = (std::is_lvalue_reference_v && std::is_class_v) // - && (std::is_lvalue_reference_v && std::is_class_v) // - && (!std::is_const_v || std::is_const_v) // - && (!std::is_volatile_v || std::is_volatile_v); // + &&(std::is_lvalue_reference_v && std::is_class_v) // + &&(!std::is_const_v || std::is_const_v) // + &&(!std::is_volatile_v || std::is_volatile_v); // } namespace meta_hpp diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 0232a82..c69a708 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -20,6 +20,7 @@ namespace meta_hpp { struct uvalue::vtable_t final { + // NOLINTBEGIN(*-avoid-const-or-ref-data-members) const any_type type; void (*const move)(uvalue&& self, uvalue& to) noexcept; @@ -29,6 +30,7 @@ namespace meta_hpp uvalue (*const deref)(const storage_u& self); uvalue (*const index)(const storage_u& self, std::size_t i); uvalue (*const unmap)(const storage_u& self); + // NOLINTEND(*-avoid-const-or-ref-data-members) template < typename T > inline static constexpr bool in_internal_v = //