mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 11:52:08 +07:00
remove "auto Variable"
This commit is contained in:
@@ -37,7 +37,7 @@ namespace meta_hpp::field_detail
|
||||
void raw_setter(
|
||||
[[maybe_unused]] FieldType field,
|
||||
[[maybe_unused]] instance instance,
|
||||
value value)
|
||||
[[maybe_unused]] value value)
|
||||
{
|
||||
using ft = detail::field_traits<FieldType>;
|
||||
using value_type = typename ft::value_type;
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace meta_hpp::method_detail
|
||||
std::optional<value> raw_cinvoke_impl(
|
||||
[[maybe_unused]] MethodType method,
|
||||
[[maybe_unused]] cinstance instance,
|
||||
value* args,
|
||||
[[maybe_unused]] value* args,
|
||||
std::index_sequence<Is...>)
|
||||
{
|
||||
using mt = detail::method_traits<MethodType>;
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < auto Variable >
|
||||
template < typename VariableType >
|
||||
class variable_ {
|
||||
public:
|
||||
explicit variable_(std::string id)
|
||||
: info_{detail::auto_arg<META_HPP_AUTO_T(Variable)>, std::move(id)} {}
|
||||
explicit variable_(std::string id, VariableType variable)
|
||||
: info_{std::move(id), variable} {}
|
||||
|
||||
operator const variable_info&() const noexcept {
|
||||
return info_;
|
||||
|
||||
@@ -14,17 +14,22 @@
|
||||
|
||||
namespace meta_hpp::variable_detail
|
||||
{
|
||||
template < typename VariableType, VariableType Variable >
|
||||
value getter() {
|
||||
template < typename VariableType >
|
||||
value raw_getter(
|
||||
VariableType variable)
|
||||
{
|
||||
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
|
||||
using value_type = typename vt::value_type;
|
||||
|
||||
value_type typed_value{*Variable};
|
||||
value_type typed_value{*variable};
|
||||
return value{std::move(typed_value)};
|
||||
}
|
||||
|
||||
template < typename VariableType, VariableType Variable >
|
||||
void setter(value value) {
|
||||
template < typename VariableType >
|
||||
void raw_setter(
|
||||
[[maybe_unused]] VariableType variable,
|
||||
[[maybe_unused]] value value)
|
||||
{
|
||||
using vt = detail::variable_traits<std::remove_reference_t<VariableType>>;
|
||||
using value_type = typename vt::value_type;
|
||||
|
||||
@@ -34,11 +39,26 @@ namespace meta_hpp::variable_detail
|
||||
throw std::logic_error("an attempt to set a variable with incorrect argument type");
|
||||
}
|
||||
|
||||
*Variable = std::move(*typed_value);
|
||||
*variable = std::move(*typed_value);
|
||||
} else {
|
||||
throw std::logic_error("an attempt to set a constant variable");
|
||||
}
|
||||
}
|
||||
|
||||
using variable_getter = std::function<value()>;
|
||||
using variable_setter = std::function<void(value)>;
|
||||
|
||||
template < typename VariableType >
|
||||
variable_getter make_getter(VariableType variable) {
|
||||
using namespace std::placeholders;
|
||||
return std::bind(&raw_getter<VariableType>, variable);
|
||||
}
|
||||
|
||||
template < typename VariableType >
|
||||
variable_setter make_setter(VariableType variable) {
|
||||
using namespace std::placeholders;
|
||||
return std::bind(&raw_setter<VariableType>, variable, _1);
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
@@ -89,18 +109,18 @@ namespace meta_hpp
|
||||
detail::merge_with(datas_, other.datas_, &data_info::merge);
|
||||
}
|
||||
private:
|
||||
template < auto Variable >
|
||||
template < typename VariableType >
|
||||
friend class variable_;
|
||||
|
||||
template < typename VariableType, VariableType Variable >
|
||||
variable_info(detail::auto_arg_t<VariableType, Variable>, std::string id)
|
||||
template < typename VariableType >
|
||||
variable_info(std::string id, VariableType variable)
|
||||
: id_{std::move(id)}
|
||||
, getter_{&variable_detail::getter<VariableType, Variable>}
|
||||
, setter_{&variable_detail::setter<VariableType, Variable>} {}
|
||||
, getter_{variable_detail::make_getter(variable)}
|
||||
, setter_{variable_detail::make_setter(variable)} {}
|
||||
private:
|
||||
std::string id_;
|
||||
value(*getter_)();
|
||||
void(*setter_)(value);
|
||||
variable_detail::variable_getter getter_;
|
||||
variable_detail::variable_setter setter_;
|
||||
std::map<std::string, data_info, std::less<>> datas_;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user