diff --git a/headers/meta.hpp/meta_field.hpp b/headers/meta.hpp/meta_field.hpp index de7f1bc..2ba7475 100644 --- a/headers/meta.hpp/meta_field.hpp +++ b/headers/meta.hpp/meta_field.hpp @@ -20,7 +20,7 @@ namespace meta_hpp static_assert(std::is_member_object_pointer_v); explicit field_(std::string id) - : info_{detail::auto_arg, std::move(id)} {} + : info_{detail::auto_arg, std::move(id)} {} operator const field_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_field_info.hpp b/headers/meta.hpp/meta_field_info.hpp index a521fdc..ce1c488 100644 --- a/headers/meta.hpp/meta_field_info.hpp +++ b/headers/meta.hpp/meta_field_info.hpp @@ -15,9 +15,9 @@ namespace meta_hpp::field_detail { - template < auto Field > + template < typename FieldType, FieldType Field > value getter(cinstance instance) { - using ft = detail::field_traits; + using ft = detail::field_traits; using value_type = typename ft::value_type; using instance_type = typename ft::instance_type; @@ -30,9 +30,9 @@ namespace meta_hpp::field_detail return value{std::move(typed_value)}; } - template < auto Field > + template < typename FieldType, FieldType Field > void setter([[maybe_unused]] instance instance, value value) { - using ft = detail::field_traits; + using ft = detail::field_traits; using value_type = typename ft::value_type; using instance_type = typename ft::instance_type; @@ -108,12 +108,12 @@ namespace meta_hpp template < auto Field > friend class field_; - template < auto Field > - field_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} + template < typename FieldType, FieldType Field > + field_info(detail::auto_arg_t, std::string id) + : fid_{get_value_family_id()} , id_{std::move(id)} - , getter_{&field_detail::getter} - , setter_{&field_detail::setter} {} + , getter_{&field_detail::getter} + , setter_{&field_detail::setter} {} private: family_id fid_; std::string id_; diff --git a/headers/meta.hpp/meta_function.hpp b/headers/meta.hpp/meta_function.hpp index 5dc110a..94a85d1 100644 --- a/headers/meta.hpp/meta_function.hpp +++ b/headers/meta.hpp/meta_function.hpp @@ -20,7 +20,7 @@ namespace meta_hpp static_assert(std::is_function_v>); explicit function_(std::string id) - : info_{detail::auto_arg, std::move(id)} {} + : info_{detail::auto_arg, std::move(id)} {} operator const function_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_function_info.hpp b/headers/meta.hpp/meta_function_info.hpp index b879529..b169858 100644 --- a/headers/meta.hpp/meta_function_info.hpp +++ b/headers/meta.hpp/meta_function_info.hpp @@ -14,9 +14,9 @@ namespace meta_hpp::function_detail { - template < auto Function, std::size_t... Is > + template < typename FunctionType, FunctionType Function, std::size_t... Is > std::optional invoke(value* args, std::index_sequence) { - using ft = detail::function_traits; + using ft = detail::function_traits; using return_type = typename ft::return_type; using argument_types = typename ft::argument_types; @@ -36,15 +36,15 @@ namespace meta_hpp::function_detail } } - template < auto Function > + template < typename FunctionType, FunctionType Function > std::optional invoke(value* args, std::size_t arg_count) { - using ft = detail::function_traits; + using ft = detail::function_traits; if ( arg_count != ft::arity ) { throw std::logic_error("an attempt to call a function with an incorrect arity"); } - return invoke(args, std::make_index_sequence()); + return invoke(args, std::make_index_sequence()); } } @@ -104,11 +104,11 @@ namespace meta_hpp template < auto Function > friend class function_; - template < auto Function > - function_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} + template < typename FunctionType, FunctionType Function > + function_info(detail::auto_arg_t, std::string id) + : fid_{get_value_family_id()} , id_{std::move(id)} - , invoke_{&function_detail::invoke} {} + , invoke_{&function_detail::invoke} {} private: family_id fid_; std::string id_; diff --git a/headers/meta.hpp/meta_fwd.hpp b/headers/meta.hpp/meta_fwd.hpp index cdd2a8e..68513c1 100644 --- a/headers/meta.hpp/meta_fwd.hpp +++ b/headers/meta.hpp/meta_fwd.hpp @@ -23,6 +23,8 @@ #include #include +#define META_HPP_AUTO_T(V) decltype(V), V + namespace meta_hpp { template < typename... Ts > @@ -77,7 +79,7 @@ namespace meta_hpp } }; - template < auto V > + template < typename T, T V > class value_family final : public family_base<> { public: static family_id id() noexcept { @@ -93,9 +95,9 @@ namespace meta_hpp return family_id_detail::type_family::id(); } - template < auto V > + template < typename T, T V > family_id get_value_family_id() noexcept { - return family_id_detail::value_family::id(); + return family_id_detail::value_family::id(); } } @@ -124,7 +126,7 @@ namespace meta_hpp namespace meta_hpp::detail { - template < auto Arg > + template < typename TArg, TArg Arg > struct auto_arg_t { }; @@ -132,8 +134,8 @@ namespace meta_hpp::detail struct typename_arg_t { }; - template < auto Arg > - inline auto_arg_t auto_arg; + template < typename TArg, TArg Arg > + inline auto_arg_t auto_arg; template < typename Arg > inline typename_arg_t typename_arg; diff --git a/headers/meta.hpp/meta_method.hpp b/headers/meta.hpp/meta_method.hpp index a179cdf..883d3fe 100644 --- a/headers/meta.hpp/meta_method.hpp +++ b/headers/meta.hpp/meta_method.hpp @@ -20,7 +20,7 @@ namespace meta_hpp static_assert(std::is_member_function_pointer_v); explicit method_(std::string id) - : info_{detail::auto_arg, std::move(id)} {} + : info_{detail::auto_arg, std::move(id)} {} operator const method_info&() const { return info_; diff --git a/headers/meta.hpp/meta_method_info.hpp b/headers/meta.hpp/meta_method_info.hpp index 91ea929..f65ca29 100644 --- a/headers/meta.hpp/meta_method_info.hpp +++ b/headers/meta.hpp/meta_method_info.hpp @@ -15,9 +15,9 @@ namespace meta_hpp::method_detail { - template < auto Method, std::size_t... Is > + template < typename MethodType, MethodType Method, std::size_t... Is > std::optional invoke(instance instance, value* args, std::index_sequence) { - using mt = detail::method_traits; + using mt = detail::method_traits; using return_type = typename mt::return_type; using instance_type = typename mt::instance_type; using argument_types = typename mt::argument_types; @@ -43,20 +43,20 @@ namespace meta_hpp::method_detail } } - template < auto Method > + template < typename MethodType, MethodType Method > std::optional invoke(instance instance, value* args, std::size_t arg_count) { - using mt = detail::method_traits; + using mt = detail::method_traits; if ( arg_count != mt::arity ) { throw std::logic_error("an attempt to call a method with an incorrect arity"); } - return invoke(instance, args, std::make_index_sequence()); + return invoke(instance, args, std::make_index_sequence()); } - template < auto Method, std::size_t... Is > + template < typename MethodType, MethodType Method, std::size_t... Is > std::optional cinvoke([[maybe_unused]] cinstance instance, value* args, std::index_sequence) { - using mt = detail::method_traits; + using mt = detail::method_traits; using return_type = typename mt::return_type; using instance_type = typename mt::instance_type; using argument_types = typename mt::argument_types; @@ -86,15 +86,15 @@ namespace meta_hpp::method_detail } } - template < auto Method > + template < typename MethodType, MethodType Method > std::optional cinvoke(cinstance instance, value* args, std::size_t arg_count) { - using mt = detail::method_traits; + using mt = detail::method_traits; if ( arg_count != mt::arity ) { throw std::logic_error("an attempt to call a method with a different arity"); } - return cinvoke(instance, args, std::make_index_sequence()); + return cinvoke(instance, args, std::make_index_sequence()); } } @@ -164,12 +164,12 @@ namespace meta_hpp template < auto Method > friend class method_; - template < auto Method > - method_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} + template < typename MethodType, MethodType Method > + method_info(detail::auto_arg_t, std::string id) + : fid_{get_value_family_id()} , id_{std::move(id)} - , invoke_{&method_detail::invoke} - , cinvoke_{&method_detail::cinvoke} {} + , invoke_{&method_detail::invoke} + , cinvoke_{&method_detail::cinvoke} {} private: family_id fid_; std::string id_; diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp index 2fdda74..0c396c1 100644 --- a/headers/meta.hpp/meta_registry.hpp +++ b/headers/meta.hpp/meta_registry.hpp @@ -27,9 +27,9 @@ namespace meta_hpp return detail::find_opt(types_, fid); } - template < auto T > + template < typename T, T V > std::optional resolve() const { - const family_id fid = get_value_family_id(); + const family_id fid = get_value_family_id(); return detail::find_opt(types_, fid); } diff --git a/headers/meta.hpp/meta_variable.hpp b/headers/meta.hpp/meta_variable.hpp index eabd19f..688ef88 100644 --- a/headers/meta.hpp/meta_variable.hpp +++ b/headers/meta.hpp/meta_variable.hpp @@ -18,7 +18,7 @@ namespace meta_hpp class variable_ { public: explicit variable_(std::string id) - : info_{detail::auto_arg, std::move(id)} {} + : info_{detail::auto_arg, std::move(id)} {} operator const variable_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_variable_info.hpp b/headers/meta.hpp/meta_variable_info.hpp index a460254..a60a83b 100644 --- a/headers/meta.hpp/meta_variable_info.hpp +++ b/headers/meta.hpp/meta_variable_info.hpp @@ -14,18 +14,18 @@ namespace meta_hpp::variable_detail { - template < auto Variable > + template < typename VariableType, VariableType Variable > value getter() { - using vt = detail::variable_traits>; + using vt = detail::variable_traits>; using value_type = typename vt::value_type; value_type typed_value{*Variable}; return value{std::move(typed_value)}; } - template < auto Variable > + template < typename VariableType, VariableType Variable > void setter(value value) { - using vt = detail::variable_traits>; + using vt = detail::variable_traits>; using value_type = typename vt::value_type; if constexpr ( !vt::is_const ) { @@ -96,12 +96,12 @@ namespace meta_hpp template < auto Variable > friend class variable_; - template < auto Variable > - variable_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} + template < typename VariableType, VariableType Variable > + variable_info(detail::auto_arg_t, std::string id) + : fid_{get_value_family_id()} , id_{std::move(id)} - , getter_{&variable_detail::getter} - , setter_{&variable_detail::setter} {} + , getter_{&variable_detail::getter} + , setter_{&variable_detail::setter} {} private: family_id fid_; std::string id_; diff --git a/untests/meta_registry_tests.cpp b/untests/meta_registry_tests.cpp index 532b6b1..3694e82 100644 --- a/untests/meta_registry_tests.cpp +++ b/untests/meta_registry_tests.cpp @@ -90,11 +90,11 @@ TEST_CASE("meta/registry") { } SUBCASE("field_template") { - REQUIRE(registry.resolve<&ivec2::x>()); - REQUIRE(registry.resolve<&ivec2::y>()); + REQUIRE(registry.resolve()); + REQUIRE(registry.resolve()); - const meta::type ivec2_x_type = registry.resolve<&ivec2::x>().value(); - const meta::type ivec2_y_type = registry.resolve<&ivec2::y>().value(); + const meta::type ivec2_x_type = registry.resolve().value(); + const meta::type ivec2_y_type = registry.resolve().value(); REQUIRE(ivec2_x_type.is_field()); REQUIRE(ivec2_y_type.is_field()); @@ -111,9 +111,9 @@ TEST_CASE("meta/registry") { } SUBCASE("function_template") { - REQUIRE(registry.resolve<&iadd2>()); + REQUIRE(registry.resolve()); - const meta::type iadd2_type = registry.resolve<&iadd2>().value(); + const meta::type iadd2_type = registry.resolve().value(); REQUIRE(iadd2_type.is_function()); const meta::function_info iadd2_info = iadd2_type.get_function().value(); @@ -125,9 +125,9 @@ TEST_CASE("meta/registry") { } SUBCASE("method_template") { - REQUIRE(registry.resolve<&ivec2::dot>()); + REQUIRE(registry.resolve()); - const meta::type ivec2_dot_type = registry.resolve<&ivec2::dot>().value(); + const meta::type ivec2_dot_type = registry.resolve().value(); REQUIRE(ivec2_dot_type.is_method()); const meta::method_info ivec2_dot_info = ivec2_dot_type.get_method().value(); @@ -139,9 +139,9 @@ TEST_CASE("meta/registry") { } SUBCASE("variable_template") { - REQUIRE(registry.resolve<&ivec2::zero>()); + REQUIRE(registry.resolve()); - const meta::type ivec2_zero_type = registry.resolve<&ivec2::zero>().value(); + const meta::type ivec2_zero_type = registry.resolve().value(); REQUIRE(ivec2_zero_type.is_variable()); const meta::variable_info ivec2_x_info = ivec2_zero_type.get_variable().value(); @@ -190,13 +190,13 @@ TEST_CASE("meta/registry") { } SUBCASE("resolve/field") { - REQUIRE(registry.resolve<&ivec2::x>()); - REQUIRE(registry.resolve<&ivec2::y>()); + REQUIRE(registry.resolve()); + REQUIRE(registry.resolve()); CHECK_FALSE(registry.resolve(&ivec2::x)); CHECK_FALSE(registry.resolve(&ivec2::y)); - REQUIRE(registry.resolve<&ivec3::x>()); - REQUIRE(registry.resolve<&ivec3::y>()); + REQUIRE(registry.resolve()); + REQUIRE(registry.resolve()); CHECK_FALSE(registry.resolve(&ivec3::x)); CHECK_FALSE(registry.resolve(&ivec3::y)); @@ -211,11 +211,11 @@ TEST_CASE("meta/registry") { CHECK(v2_x_info.fid() != v3_x_info.fid()); CHECK(v2_y_info.fid() != v3_y_info.fid()); - CHECK(v2_x_info.fid() == registry.resolve<&ivec2::x>()->get_field()->fid()); - CHECK(v2_y_info.fid() == registry.resolve<&ivec2::y>()->get_field()->fid()); + CHECK(v2_x_info.fid() == registry.resolve()->get_field()->fid()); + CHECK(v2_y_info.fid() == registry.resolve()->get_field()->fid()); - CHECK(v3_x_info.fid() == registry.resolve<&ivec3::x>()->get_field()->fid()); - CHECK(v3_y_info.fid() == registry.resolve<&ivec3::y>()->get_field()->fid()); + CHECK(v3_x_info.fid() == registry.resolve()->get_field()->fid()); + CHECK(v3_y_info.fid() == registry.resolve()->get_field()->fid()); { REQUIRE(registry.get_field_by_name("vmath::ivec2::x")); @@ -231,8 +231,8 @@ TEST_CASE("meta/registry") { } SUBCASE("resolve/function") { - REQUIRE(registry.resolve<&iadd2>()); - REQUIRE(registry.resolve<&iadd3>()); + REQUIRE(registry.resolve()); + REQUIRE(registry.resolve()); CHECK_FALSE(registry.resolve(&iadd2)); CHECK_FALSE(registry.resolve(&iadd3)); @@ -240,8 +240,8 @@ TEST_CASE("meta/registry") { const meta::function_info iadd3_info = meta::function_<&iadd3>("iadd3"); CHECK(iadd2_info.fid() != iadd3_info.fid()); - CHECK(iadd2_info.fid() == registry.resolve<&iadd2>()->get_function()->fid()); - CHECK(iadd3_info.fid() == registry.resolve<&iadd3>()->get_function()->fid()); + CHECK(iadd2_info.fid() == registry.resolve()->get_function()->fid()); + CHECK(iadd3_info.fid() == registry.resolve()->get_function()->fid()); { REQUIRE(registry.get_function_by_name("vmath::iadd2")); @@ -253,8 +253,8 @@ TEST_CASE("meta/registry") { } SUBCASE("resolve/method") { - REQUIRE(registry.resolve<&ivec2::dot>()); - REQUIRE(registry.resolve<&ivec3::dot>()); + REQUIRE(registry.resolve()); + REQUIRE(registry.resolve()); CHECK_FALSE(registry.resolve(&ivec2::dot)); CHECK_FALSE(registry.resolve(&ivec3::dot)); @@ -262,8 +262,8 @@ TEST_CASE("meta/registry") { const meta::method_info v3_dot_info = meta::method_<&ivec3::dot>("dot"); CHECK(v2_dot_info.fid() != v3_dot_info.fid()); - CHECK(v2_dot_info.fid() == registry.resolve<&ivec2::dot>()->get_method()->fid()); - CHECK(v3_dot_info.fid() == registry.resolve<&ivec3::dot>()->get_method()->fid()); + CHECK(v2_dot_info.fid() == registry.resolve()->get_method()->fid()); + CHECK(v3_dot_info.fid() == registry.resolve()->get_method()->fid()); { REQUIRE(registry.get_method_by_name("vmath::ivec2::dot")); @@ -275,8 +275,8 @@ TEST_CASE("meta/registry") { } SUBCASE("resolve/variable") { - REQUIRE(registry.resolve<&ivec2::zero>()); - REQUIRE(registry.resolve<&ivec3::zero>()); + REQUIRE(registry.resolve()); + REQUIRE(registry.resolve()); CHECK_FALSE(registry.resolve(&ivec2::zero)); CHECK_FALSE(registry.resolve(&ivec3::zero)); @@ -284,8 +284,8 @@ TEST_CASE("meta/registry") { const meta::variable_info v3_zero_info = meta::variable_<&ivec3::zero>("zero"); CHECK(v2_zero_info.fid() != v3_zero_info.fid()); - CHECK(v2_zero_info.fid() == registry.resolve<&ivec2::zero>()->get_variable()->fid()); - CHECK(v3_zero_info.fid() == registry.resolve<&ivec3::zero>()->get_variable()->fid()); + CHECK(v2_zero_info.fid() == registry.resolve()->get_variable()->fid()); + CHECK(v3_zero_info.fid() == registry.resolve()->get_variable()->fid()); { REQUIRE(registry.get_variable_by_name("vmath::ivec2::zero"));