mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 14:09:02 +07:00
remove "auto Function"
This commit is contained in:
@@ -14,13 +14,13 @@
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < auto Function >
|
||||
template < typename FunctionType >
|
||||
class function_ {
|
||||
public:
|
||||
static_assert(std::is_function_v<std::remove_pointer_t<decltype(Function)>>);
|
||||
static_assert(std::is_function_v<std::remove_pointer_t<FunctionType>>);
|
||||
|
||||
explicit function_(std::string id)
|
||||
: info_{detail::auto_arg<META_HPP_AUTO_T(Function)>, std::move(id)} {}
|
||||
explicit function_(std::string id, FunctionType function)
|
||||
: info_{std::move(id), function} {}
|
||||
|
||||
operator const function_info&() const noexcept {
|
||||
return info_;
|
||||
|
||||
@@ -14,8 +14,12 @@
|
||||
|
||||
namespace meta_hpp::function_detail
|
||||
{
|
||||
template < typename FunctionType, FunctionType Function, std::size_t... Is >
|
||||
std::optional<value> invoke(value* args, std::index_sequence<Is...>) {
|
||||
template < typename FunctionType, std::size_t... Is >
|
||||
std::optional<value> raw_invoke_impl(
|
||||
FunctionType function,
|
||||
value* args,
|
||||
std::index_sequence<Is...>)
|
||||
{
|
||||
using ft = detail::function_traits<FunctionType>;
|
||||
using return_type = typename ft::return_type;
|
||||
using argument_types = typename ft::argument_types;
|
||||
@@ -28,23 +32,35 @@ namespace meta_hpp::function_detail
|
||||
}
|
||||
|
||||
if constexpr ( std::is_void_v<return_type> ) {
|
||||
std::invoke(Function, std::move(*std::get<Is>(typed_arguments))...);
|
||||
std::invoke(function, std::move(*std::get<Is>(typed_arguments))...);
|
||||
return std::nullopt;
|
||||
} else {
|
||||
return_type return_value{std::invoke(Function, std::move(*std::get<Is>(typed_arguments))...)};
|
||||
return_type return_value{std::invoke(function, std::move(*std::get<Is>(typed_arguments))...)};
|
||||
return value{std::move(return_value)};
|
||||
}
|
||||
}
|
||||
|
||||
template < typename FunctionType, FunctionType Function >
|
||||
std::optional<value> invoke(value* args, std::size_t arg_count) {
|
||||
template < typename FunctionType >
|
||||
std::optional<value> raw_invoke(
|
||||
FunctionType function,
|
||||
value* args,
|
||||
std::size_t arg_count)
|
||||
{
|
||||
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<FunctionType, Function>(args, std::make_index_sequence<ft::arity>());
|
||||
return raw_invoke_impl<FunctionType>(function, args, std::make_index_sequence<ft::arity>());
|
||||
}
|
||||
|
||||
using function_invoke = std::function<std::optional<value>(value*, std::size_t)>;
|
||||
|
||||
template < typename FunctionType >
|
||||
function_invoke make_invoke(FunctionType function) {
|
||||
using namespace std::placeholders;
|
||||
return std::bind(&raw_invoke<FunctionType>, function, _1, _2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,16 +113,16 @@ namespace meta_hpp
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||
}
|
||||
private:
|
||||
template < auto Function >
|
||||
template < typename FunctionType >
|
||||
friend class function_;
|
||||
|
||||
template < typename FunctionType, FunctionType Function >
|
||||
function_info(detail::auto_arg_t<FunctionType, Function>, std::string id)
|
||||
template < typename FunctionType >
|
||||
function_info(std::string id, FunctionType function)
|
||||
: id_{std::move(id)}
|
||||
, invoke_{&function_detail::invoke<FunctionType, Function>} {}
|
||||
, invoke_{function_detail::make_invoke(function)} {}
|
||||
private:
|
||||
std::string id_;
|
||||
std::optional<value>(*invoke_)(value*, std::size_t);
|
||||
function_detail::function_invoke invoke_;
|
||||
std::map<std::string, data_info, std::less<>> datas_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ TEST_CASE("meta/class") {
|
||||
meta::class_<clazz::clazz2>("clazz2"),
|
||||
meta::field_("field", &clazz::field),
|
||||
meta::field_("cfield", &clazz::cfield),
|
||||
meta::function_<&clazz::func>("func"),
|
||||
meta::function_("func", &clazz::func),
|
||||
meta::method_("method", &clazz::method),
|
||||
meta::method_("cmethod", &clazz::cmethod),
|
||||
meta::variable_<&clazz::variable>("variable"),
|
||||
|
||||
@@ -115,7 +115,7 @@ TEST_CASE("meta/data/function") {
|
||||
using namespace std::string_literals;
|
||||
|
||||
const meta::class_info clazz_info = meta::class_<clazz>("clazz")(
|
||||
meta::function_<&clazz::function>("function")(
|
||||
meta::function_("function", &clazz::function)(
|
||||
meta::data_("hello"s, "world"s)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -111,8 +111,8 @@ TEST_CASE("meta/examples/simple") {
|
||||
method_("dot", &ivec3::dot),
|
||||
method_("length2", &ivec3::length2)
|
||||
),
|
||||
function_<select<ivec2(ivec2,ivec2)>(&add)>("iadd2"),
|
||||
function_<select<ivec3(ivec3,ivec3)>(&add)>("iadd3")
|
||||
function_("iadd2", select<ivec2(ivec2,ivec2)>(&add)),
|
||||
function_("iadd3", select<ivec3(ivec3,ivec3)>(&add))
|
||||
);
|
||||
|
||||
class_info ivec2_info = vmath_info.get_class("ivec2").value();
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace
|
||||
TEST_CASE("meta/function") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::function_<&void_f_void> void_f_void_function_("void_f_void");
|
||||
meta::function_<&void_f_int> void_f_int_function_("void_f_int");
|
||||
meta::function_<&void_f_int2> void_f_int2_function_("void_f_int2");
|
||||
meta::function_ void_f_void_function_("void_f_void", &void_f_void);
|
||||
meta::function_ void_f_int_function_("void_f_int", &void_f_int);
|
||||
meta::function_ void_f_int2_function_("void_f_int2", &void_f_int2);
|
||||
|
||||
meta::function_<&int_f_void> int_f_void_function_("int_f_void");
|
||||
meta::function_<&int_f_int> int_f_int_function_("int_f_int");
|
||||
meta::function_<&int_f_int2> int_f_int2_function_("int_f_int2");
|
||||
meta::function_ int_f_void_function_("int_f_void", &int_f_void);
|
||||
meta::function_ int_f_int_function_("int_f_int", &int_f_int);
|
||||
meta::function_ int_f_int2_function_("int_f_int2", &int_f_int2);
|
||||
|
||||
const meta::function_info& void_f_void_info = void_f_void_function_;
|
||||
const meta::function_info& void_f_int_info = void_f_int_function_;
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_CASE("meta/namespace") {
|
||||
|
||||
namespace_(
|
||||
meta::class_<clazz>("clazz"),
|
||||
meta::function_<&func>("func"),
|
||||
meta::function_("func", &func),
|
||||
meta::namespace_("ns2"),
|
||||
meta::variable_<&variable>("variable"),
|
||||
meta::variable_<&cvariable>("cvariable"));
|
||||
@@ -80,7 +80,7 @@ TEST_CASE("meta/namespace/merge") {
|
||||
namespace_(
|
||||
meta::namespace_{"ns2"}(
|
||||
meta::class_<clazz>{"clazz"},
|
||||
meta::function_<&func>("func"),
|
||||
meta::function_("func", &func),
|
||||
meta::namespace_{"ns3"},
|
||||
meta::variable_<&variable>("variable")
|
||||
)
|
||||
@@ -89,7 +89,7 @@ TEST_CASE("meta/namespace/merge") {
|
||||
namespace_(
|
||||
meta::namespace_{"ns2"}(
|
||||
meta::class_<clazz>{"clazz"},
|
||||
meta::function_<&func>("func2"),
|
||||
meta::function_("func2", &func),
|
||||
meta::namespace_{"ns3"}(
|
||||
meta::namespace_{"ns4"},
|
||||
meta::variable_<&variable>("variable2")
|
||||
|
||||
@@ -63,8 +63,8 @@ TEST_CASE("meta/registry") {
|
||||
meta::method_("dot", &ivec3::dot),
|
||||
meta::variable_<&ivec3::zero>("zero")
|
||||
),
|
||||
meta::function_<&iadd2>("iadd2"),
|
||||
meta::function_<&iadd3>("iadd3")
|
||||
meta::function_("iadd2", &iadd2),
|
||||
meta::function_("iadd3", &iadd3)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST_CASE("meta/type") {
|
||||
CHECK(field_type.is_field());
|
||||
CHECK(field_type.get_field()->id() == "field");
|
||||
|
||||
meta::type function_type = meta::function_<&clazz::function>("function");
|
||||
meta::type function_type = meta::function_("function", &clazz::function);
|
||||
CHECK(function_type.is_function());
|
||||
CHECK(function_type.get_function()->id() == "function");
|
||||
|
||||
@@ -66,7 +66,7 @@ TEST_CASE("meta/type/merge") {
|
||||
);
|
||||
|
||||
clazz_type.merge(meta::class_<clazz>("clazz")(
|
||||
meta::function_<&clazz::function>("function")
|
||||
meta::function_("function", &clazz::function)
|
||||
));
|
||||
|
||||
REQUIRE(clazz_type.is_class());
|
||||
|
||||
Reference in New Issue
Block a user