remove auto templates usage

This commit is contained in:
BlackMATov
2021-07-06 22:20:23 +07:00
parent 6c64df3bce
commit e471b3b70a
11 changed files with 86 additions and 84 deletions

View File

@@ -20,7 +20,7 @@ namespace meta_hpp
static_assert(std::is_member_object_pointer_v<decltype(Field)>);
explicit field_(std::string id)
: info_{detail::auto_arg<Field>, std::move(id)} {}
: info_{detail::auto_arg<META_HPP_AUTO_T(Field)>, std::move(id)} {}
operator const field_info&() const noexcept {
return info_;

View File

@@ -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<decltype(Field)>;
using ft = detail::field_traits<FieldType>;
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<decltype(Field)>;
using ft = detail::field_traits<FieldType>;
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<Field>, std::string id)
: fid_{get_value_family_id<Field>()}
template < typename FieldType, FieldType Field >
field_info(detail::auto_arg_t<FieldType, Field>, std::string id)
: fid_{get_value_family_id<FieldType, Field>()}
, id_{std::move(id)}
, getter_{&field_detail::getter<Field>}
, setter_{&field_detail::setter<Field>} {}
, getter_{&field_detail::getter<FieldType, Field>}
, setter_{&field_detail::setter<FieldType, Field>} {}
private:
family_id fid_;
std::string id_;

View File

@@ -20,7 +20,7 @@ namespace meta_hpp
static_assert(std::is_function_v<std::remove_pointer_t<decltype(Function)>>);
explicit function_(std::string id)
: info_{detail::auto_arg<Function>, std::move(id)} {}
: info_{detail::auto_arg<META_HPP_AUTO_T(Function)>, std::move(id)} {}
operator const function_info&() const noexcept {
return info_;

View File

@@ -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<value> invoke(value* args, std::index_sequence<Is...>) {
using ft = detail::function_traits<decltype(Function)>;
using ft = detail::function_traits<FunctionType>;
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<value> invoke(value* args, std::size_t arg_count) {
using ft = detail::function_traits<decltype(Function)>;
using ft = detail::function_traits<FunctionType>;
if ( arg_count != ft::arity ) {
throw std::logic_error("an attempt to call a function with an incorrect arity");
}
return invoke<Function>(args, std::make_index_sequence<ft::arity>());
return invoke<FunctionType, Function>(args, std::make_index_sequence<ft::arity>());
}
}
@@ -104,11 +104,11 @@ namespace meta_hpp
template < auto Function >
friend class function_;
template < auto Function >
function_info(detail::auto_arg_t<Function>, std::string id)
: fid_{get_value_family_id<Function>()}
template < typename FunctionType, FunctionType Function >
function_info(detail::auto_arg_t<FunctionType, Function>, std::string id)
: fid_{get_value_family_id<FunctionType, Function>()}
, id_{std::move(id)}
, invoke_{&function_detail::invoke<Function>} {}
, invoke_{&function_detail::invoke<FunctionType, Function>} {}
private:
family_id fid_;
std::string id_;

View File

@@ -23,6 +23,8 @@
#include <utility>
#include <variant>
#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<T>::id();
}
template < auto V >
template < typename T, T V >
family_id get_value_family_id() noexcept {
return family_id_detail::value_family<V>::id();
return family_id_detail::value_family<T, V>::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<Arg> auto_arg;
template < typename TArg, TArg Arg >
inline auto_arg_t<TArg, Arg> auto_arg;
template < typename Arg >
inline typename_arg_t<Arg> typename_arg;

View File

@@ -20,7 +20,7 @@ namespace meta_hpp
static_assert(std::is_member_function_pointer_v<decltype(Method)>);
explicit method_(std::string id)
: info_{detail::auto_arg<Method>, std::move(id)} {}
: info_{detail::auto_arg<META_HPP_AUTO_T(Method)>, std::move(id)} {}
operator const method_info&() const {
return info_;

View File

@@ -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<value> invoke(instance instance, value* args, std::index_sequence<Is...>) {
using mt = detail::method_traits<decltype(Method)>;
using mt = detail::method_traits<MethodType>;
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<value> invoke(instance instance, value* args, std::size_t arg_count) {
using mt = detail::method_traits<decltype(Method)>;
using mt = detail::method_traits<MethodType>;
if ( arg_count != mt::arity ) {
throw std::logic_error("an attempt to call a method with an incorrect arity");
}
return invoke<Method>(instance, args, std::make_index_sequence<mt::arity>());
return invoke<MethodType, Method>(instance, args, std::make_index_sequence<mt::arity>());
}
template < auto Method, std::size_t... Is >
template < typename MethodType, MethodType Method, std::size_t... Is >
std::optional<value> cinvoke([[maybe_unused]] cinstance instance, value* args, std::index_sequence<Is...>) {
using mt = detail::method_traits<decltype(Method)>;
using mt = detail::method_traits<MethodType>;
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<value> cinvoke(cinstance instance, value* args, std::size_t arg_count) {
using mt = detail::method_traits<decltype(Method)>;
using mt = detail::method_traits<MethodType>;
if ( arg_count != mt::arity ) {
throw std::logic_error("an attempt to call a method with a different arity");
}
return cinvoke<Method>(instance, args, std::make_index_sequence<mt::arity>());
return cinvoke<MethodType, Method>(instance, args, std::make_index_sequence<mt::arity>());
}
}
@@ -164,12 +164,12 @@ namespace meta_hpp
template < auto Method >
friend class method_;
template < auto Method >
method_info(detail::auto_arg_t<Method>, std::string id)
: fid_{get_value_family_id<Method>()}
template < typename MethodType, MethodType Method >
method_info(detail::auto_arg_t<MethodType, Method>, std::string id)
: fid_{get_value_family_id<MethodType, Method>()}
, id_{std::move(id)}
, invoke_{&method_detail::invoke<Method>}
, cinvoke_{&method_detail::cinvoke<Method>} {}
, invoke_{&method_detail::invoke<MethodType, Method>}
, cinvoke_{&method_detail::cinvoke<MethodType, Method>} {}
private:
family_id fid_;
std::string id_;

View File

@@ -27,9 +27,9 @@ namespace meta_hpp
return detail::find_opt(types_, fid);
}
template < auto T >
template < typename T, T V >
std::optional<type> resolve() const {
const family_id fid = get_value_family_id<T>();
const family_id fid = get_value_family_id<T, V>();
return detail::find_opt(types_, fid);
}

View File

@@ -18,7 +18,7 @@ namespace meta_hpp
class variable_ {
public:
explicit variable_(std::string id)
: info_{detail::auto_arg<Variable>, std::move(id)} {}
: info_{detail::auto_arg<META_HPP_AUTO_T(Variable)>, std::move(id)} {}
operator const variable_info&() const noexcept {
return info_;

View File

@@ -14,18 +14,18 @@
namespace meta_hpp::variable_detail
{
template < auto Variable >
template < typename VariableType, VariableType Variable >
value getter() {
using vt = detail::variable_traits<std::remove_reference_t<decltype(Variable)>>;
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
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<std::remove_reference_t<decltype(Variable)>>;
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
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<Variable>, std::string id)
: fid_{get_value_family_id<Variable>()}
template < typename VariableType, VariableType Variable >
variable_info(detail::auto_arg_t<VariableType, Variable>, std::string id)
: fid_{get_value_family_id<VariableType, Variable>()}
, id_{std::move(id)}
, getter_{&variable_detail::getter<Variable>}
, setter_{&variable_detail::setter<Variable>} {}
, getter_{&variable_detail::getter<VariableType, Variable>}
, setter_{&variable_detail::setter<VariableType, Variable>} {}
private:
family_id fid_;
std::string id_;

View File

@@ -90,11 +90,11 @@ TEST_CASE("meta/registry") {
}
SUBCASE("field_template") {
REQUIRE(registry.resolve<&ivec2::x>());
REQUIRE(registry.resolve<&ivec2::y>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::x)>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::y)>());
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<META_HPP_AUTO_T(&ivec2::x)>().value();
const meta::type ivec2_y_type = registry.resolve<META_HPP_AUTO_T(&ivec2::y)>().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<META_HPP_AUTO_T(&iadd2)>());
const meta::type iadd2_type = registry.resolve<&iadd2>().value();
const meta::type iadd2_type = registry.resolve<META_HPP_AUTO_T(&iadd2)>().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<META_HPP_AUTO_T(&ivec2::dot)>());
const meta::type ivec2_dot_type = registry.resolve<&ivec2::dot>().value();
const meta::type ivec2_dot_type = registry.resolve<META_HPP_AUTO_T(&ivec2::dot)>().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<META_HPP_AUTO_T(&ivec2::zero)>());
const meta::type ivec2_zero_type = registry.resolve<&ivec2::zero>().value();
const meta::type ivec2_zero_type = registry.resolve<META_HPP_AUTO_T(&ivec2::zero)>().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<META_HPP_AUTO_T(&ivec2::x)>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec2::y)>());
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<META_HPP_AUTO_T(&ivec3::x)>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::y)>());
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<META_HPP_AUTO_T(&ivec2::x)>()->get_field()->fid());
CHECK(v2_y_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec2::y)>()->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<META_HPP_AUTO_T(&ivec3::x)>()->get_field()->fid());
CHECK(v3_y_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::y)>()->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<META_HPP_AUTO_T(&iadd2)>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&iadd3)>());
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<META_HPP_AUTO_T(&iadd2)>()->get_function()->fid());
CHECK(iadd3_info.fid() == registry.resolve<META_HPP_AUTO_T(&iadd3)>()->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<META_HPP_AUTO_T(&ivec2::dot)>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::dot)>());
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<META_HPP_AUTO_T(&ivec2::dot)>()->get_method()->fid());
CHECK(v3_dot_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::dot)>()->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<META_HPP_AUTO_T(&ivec2::zero)>());
REQUIRE(registry.resolve<META_HPP_AUTO_T(&ivec3::zero)>());
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<META_HPP_AUTO_T(&ivec2::zero)>()->get_variable()->fid());
CHECK(v3_zero_info.fid() == registry.resolve<META_HPP_AUTO_T(&ivec3::zero)>()->get_variable()->fid());
{
REQUIRE(registry.get_variable_by_name("vmath::ivec2::zero"));