rename: arg -> uarg, inst -> uinst, value -> uvalue

This commit is contained in:
BlackMATov
2022-02-08 20:45:08 +07:00
parent 40b76839d8
commit 8e18c85823
41 changed files with 1053 additions and 1053 deletions

View File

@@ -89,15 +89,15 @@ namespace meta_hpp
namespace meta_hpp
{
class value;
class uvalue;
namespace detail
{
class arg_base;
class arg;
class uarg_base;
class uarg;
class inst_base;
class inst;
class uinst_base;
class uinst;
}
}

View File

@@ -16,7 +16,7 @@ namespace meta_hpp::detail
template < typename T >
concept has_deref_traits = requires(const T& v) {
{ deref_traits<T>{}(v) } -> stdex::convertible_to<value>;
{ deref_traits<T>{}(v) } -> stdex::convertible_to<uvalue>;
};
}
@@ -24,29 +24,29 @@ namespace meta_hpp::detail
{
template < stdex::copy_constructible T >
struct deref_traits<T*> {
value operator()(T* v) const {
return value{*v};
uvalue operator()(T* v) const {
return uvalue{*v};
}
};
template < stdex::copy_constructible T >
struct deref_traits<const T*> {
value operator()(const T* v) const {
return value{*v};
uvalue operator()(const T* v) const {
return uvalue{*v};
}
};
template < stdex::copy_constructible T >
struct deref_traits<std::shared_ptr<T>> {
value operator()(const std::shared_ptr<T>& v) const {
return value{*v};
uvalue operator()(const std::shared_ptr<T>& v) const {
return uvalue{*v};
}
};
template < stdex::copy_constructible T >
struct deref_traits<std::unique_ptr<T>> {
value operator()(const std::unique_ptr<T>& v) const {
return value{*v};
uvalue operator()(const std::unique_ptr<T>& v) const {
return uvalue{*v};
}
};
}

View File

@@ -16,7 +16,7 @@ namespace meta_hpp::detail
template < typename T >
concept has_index_traits = requires(const T& v, std::size_t i) {
{ index_traits<T>{}(v, i) } -> stdex::convertible_to<value>;
{ index_traits<T>{}(v, i) } -> stdex::convertible_to<uvalue>;
};
}
@@ -24,43 +24,43 @@ namespace meta_hpp::detail
{
template < stdex::copy_constructible T >
struct index_traits<T*> {
value operator()(T* v, std::size_t i) const {
return value{v[i]};
uvalue operator()(T* v, std::size_t i) const {
return uvalue{v[i]};
}
};
template < stdex::copy_constructible T >
struct index_traits<const T*> {
value operator()(const T* v, std::size_t i) const {
return value{v[i]};
uvalue operator()(const T* v, std::size_t i) const {
return uvalue{v[i]};
}
};
template < stdex::copy_constructible T, std::size_t Size >
struct index_traits<std::array<T, Size>> {
value operator()(const std::array<T, Size>& v, std::size_t i) const {
return value{v[i]};
uvalue operator()(const std::array<T, Size>& v, std::size_t i) const {
return uvalue{v[i]};
}
};
template < stdex::copy_constructible T, std::size_t Extent >
struct index_traits<std::span<T, Extent>> {
value operator()(const std::span<T, Extent>& v, std::size_t i) const {
return value{v[i]};
uvalue operator()(const std::span<T, Extent>& v, std::size_t i) const {
return uvalue{v[i]};
}
};
template < stdex::copy_constructible T, typename Traits, typename Allocator >
struct index_traits<std::basic_string<T, Traits, Allocator>> {
value operator()(const std::basic_string<T, Traits, Allocator>& v, std::size_t i) const {
return value{v[i]};
uvalue operator()(const std::basic_string<T, Traits, Allocator>& v, std::size_t i) const {
return uvalue{v[i]};
}
};
template < stdex::copy_constructible T, typename Allocator >
struct index_traits<std::vector<T, Allocator>> {
value operator()(const std::vector<T, Allocator>& v, std::size_t i) {
return value{v[i]};
uvalue operator()(const std::vector<T, Allocator>& v, std::size_t i) {
return uvalue{v[i]};
}
};
}

View File

@@ -13,7 +13,7 @@
namespace meta_hpp::detail
{
class arg_base {
class uarg_base {
public:
enum class ref_types {
lvalue,
@@ -22,29 +22,29 @@ namespace meta_hpp::detail
const_rvalue,
};
public:
arg_base() = delete;
uarg_base() = delete;
arg_base(arg_base&&) = default;
arg_base(const arg_base&) = default;
uarg_base(uarg_base&&) = default;
uarg_base(const uarg_base&) = default;
arg_base& operator=(arg_base&&) = delete;
arg_base& operator=(const arg_base&) = delete;
uarg_base& operator=(uarg_base&&) = delete;
uarg_base& operator=(const uarg_base&) = delete;
virtual ~arg_base() = default;
virtual ~uarg_base() = default;
template < decay_value_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit arg_base(T&&)
: arg_base{type_list<T&&>{}} {}
explicit uarg_base(T&&)
: uarg_base{type_list<T&&>{}} {}
template < decay_non_uvalue_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit arg_base(T&&)
: arg_base{type_list<T&&>{}} {}
explicit uarg_base(T&&)
: uarg_base{type_list<T&&>{}} {}
template < arg_lvalue_ref_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit arg_base(type_list<T>)
explicit uarg_base(type_list<T>)
: ref_type_{std::is_const_v<std::remove_reference_t<T>>
? ref_types::const_lvalue
: ref_types::lvalue}
@@ -52,25 +52,25 @@ namespace meta_hpp::detail
template < arg_rvalue_ref_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit arg_base(type_list<T>)
explicit uarg_base(type_list<T>)
: ref_type_{std::is_const_v<std::remove_reference_t<T>>
? ref_types::const_rvalue
: ref_types::rvalue}
, raw_type_{resolve_type<std::remove_cvref_t<T>>()} {}
explicit arg_base(value& v)
explicit uarg_base(uvalue& v)
: ref_type_{ref_types::lvalue}
, raw_type_{v.get_type()} {}
explicit arg_base(const value& v)
explicit uarg_base(const uvalue& v)
: ref_type_{ref_types::const_lvalue}
, raw_type_{v.get_type()} {}
explicit arg_base(value&& v)
explicit uarg_base(uvalue&& v)
: ref_type_{ref_types::rvalue}
, raw_type_{v.get_type()} {}
explicit arg_base(const value&& v)
explicit uarg_base(const uvalue&& v)
: ref_type_{ref_types::const_rvalue}
, raw_type_{v.get_type()} {}
@@ -107,27 +107,27 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
class arg final : public arg_base {
class uarg final : public uarg_base {
public:
arg() = delete;
uarg() = delete;
arg(arg&&) = default;
arg(const arg&) = default;
uarg(uarg&&) = default;
uarg(const uarg&) = default;
arg& operator=(arg&&) = delete;
arg& operator=(const arg&) = delete;
uarg& operator=(uarg&&) = delete;
uarg& operator=(const uarg&) = delete;
~arg() override = default;
~uarg() override = default;
template < decay_value_kind T >
explicit arg(T&& v)
: arg_base{std::forward<T>(v)}
explicit uarg(T&& v)
: uarg_base{std::forward<T>(v)}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
, data_{const_cast<void*>(v.data())} {}
template < decay_non_uvalue_kind T >
explicit arg(T&& v)
: arg_base{std::forward<T>(v)}
explicit uarg(T&& v)
: uarg_base{std::forward<T>(v)}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
, data_{const_cast<std::remove_cvref_t<T>*>(std::addressof(v))} {}
@@ -142,7 +142,7 @@ namespace meta_hpp::detail
{
template < typename To >
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
bool arg_base::can_cast_to() const noexcept {
bool uarg_base::can_cast_to() const noexcept {
using to_raw_type_cv = std::remove_reference_t<To>;
using to_raw_type = std::remove_cv_t<to_raw_type_cv>;
@@ -248,7 +248,7 @@ namespace meta_hpp::detail
{
template < typename To >
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
To arg::cast() const {
To uarg::cast() const {
if ( !can_cast_to<To>() ) {
throw_exception_with("bad argument cast");
}

View File

@@ -13,7 +13,7 @@
namespace meta_hpp::detail
{
class inst_base {
class uinst_base {
public:
enum class ref_types {
lvalue,
@@ -22,29 +22,29 @@ namespace meta_hpp::detail
const_rvalue,
};
public:
inst_base() = delete;
uinst_base() = delete;
inst_base(inst_base&&) = default;
inst_base(const inst_base&) = default;
uinst_base(uinst_base&&) = default;
uinst_base(const uinst_base&) = default;
inst_base& operator=(inst_base&&) = delete;
inst_base& operator=(const inst_base&) = delete;
uinst_base& operator=(uinst_base&&) = delete;
uinst_base& operator=(const uinst_base&) = delete;
virtual ~inst_base() = default;
virtual ~uinst_base() = default;
template < decay_value_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit inst_base(T&&)
: inst_base{type_list<T&&>{}} {}
explicit uinst_base(T&&)
: uinst_base{type_list<T&&>{}} {}
template < decay_non_uvalue_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit inst_base(T&&)
: inst_base{type_list<T&&>{}} {}
explicit uinst_base(T&&)
: uinst_base{type_list<T&&>{}} {}
template < inst_class_lvalue_ref_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit inst_base(type_list<T>)
explicit uinst_base(type_list<T>)
: ref_type_{std::is_const_v<std::remove_reference_t<T>>
? ref_types::const_lvalue
: ref_types::lvalue}
@@ -52,25 +52,25 @@ namespace meta_hpp::detail
template < inst_class_rvalue_ref_kind T >
// NOLINTNEXTLINE(readability-named-parameter)
explicit inst_base(type_list<T>)
explicit uinst_base(type_list<T>)
: ref_type_{std::is_const_v<std::remove_reference_t<T>>
? ref_types::const_rvalue
: ref_types::rvalue}
, raw_type_{resolve_type<std::remove_cvref_t<T>>()} {}
explicit inst_base(value& v)
explicit uinst_base(uvalue& v)
: ref_type_{ref_types::lvalue}
, raw_type_{v.get_type()} {}
explicit inst_base(const value& v)
explicit uinst_base(const uvalue& v)
: ref_type_{ref_types::const_lvalue}
, raw_type_{v.get_type()} {}
explicit inst_base(value&& v)
explicit uinst_base(uvalue&& v)
: ref_type_{ref_types::rvalue}
, raw_type_{v.get_type()} {}
explicit inst_base(const value&& v)
explicit uinst_base(const uvalue&& v)
: ref_type_{ref_types::const_rvalue}
, raw_type_{v.get_type()} {}
@@ -107,27 +107,27 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
class inst final : public inst_base {
class uinst final : public uinst_base {
public:
inst() = delete;
uinst() = delete;
inst(inst&&) = default;
inst(const inst&) = default;
uinst(uinst&&) = default;
uinst(const uinst&) = default;
inst& operator=(inst&&) = delete;
inst& operator=(const inst&) = delete;
uinst& operator=(uinst&&) = delete;
uinst& operator=(const uinst&) = delete;
~inst() override = default;
~uinst() override = default;
template < decay_value_kind T >
explicit inst(T&& v)
: inst_base{std::forward<T>(v)}
explicit uinst(T&& v)
: uinst_base{std::forward<T>(v)}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
, data_{const_cast<void*>(v.data())} {}
template < decay_non_uvalue_kind T >
explicit inst(T&& v)
: inst_base{std::forward<T>(v)}
explicit uinst(T&& v)
: uinst_base{std::forward<T>(v)}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
, data_{const_cast<std::remove_cvref_t<T>*>(std::addressof(v))} {}
@@ -141,7 +141,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < inst_class_ref_kind Q >
bool inst_base::can_cast_to() const noexcept {
bool uinst_base::can_cast_to() const noexcept {
using inst_class = typename inst_traits<Q>::class_type;
using inst_method = typename inst_traits<Q>::method_type;
@@ -175,7 +175,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < inst_class_ref_kind Q >
decltype(auto) inst::cast() const {
decltype(auto) uinst::cast() const {
if ( !can_cast_to<Q>() ) {
throw_exception_with("bad instance cast");
}

View File

@@ -13,11 +13,11 @@ namespace meta_hpp::detail
{
template < typename T >
inline constexpr bool is_uvalue_kind_v =
std::is_same_v<T, arg_base> ||
std::is_same_v<T, arg> ||
std::is_same_v<T, inst_base> ||
std::is_same_v<T, inst> ||
std::is_same_v<T, value>;
std::is_same_v<T, uarg_base> ||
std::is_same_v<T, uarg> ||
std::is_same_v<T, uinst_base> ||
std::is_same_v<T, uinst> ||
std::is_same_v<T, uvalue>;
template < typename T >
concept uvalue_kind = is_uvalue_kind_v<T>;

View File

@@ -110,10 +110,10 @@ namespace meta_hpp
[[nodiscard]] const ctor_type& get_type() const noexcept;
template < typename... Args >
value invoke(Args&&... args) const;
uvalue invoke(Args&&... args) const;
template < typename... Args >
value operator()(Args&&... args) const;
uvalue operator()(Args&&... args) const;
template < typename... Args >
[[nodiscard]] bool is_invocable_with() const noexcept;
@@ -167,8 +167,8 @@ namespace meta_hpp
[[nodiscard]] const enum_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
[[nodiscard]] const value& get_value() const noexcept;
[[nodiscard]] const value& get_underlying_value() const noexcept;
[[nodiscard]] const uvalue& get_value() const noexcept;
[[nodiscard]] const uvalue& get_underlying_value() const noexcept;
private:
detail::evalue_state_ptr state_;
friend auto detail::state_access<evalue>(const evalue&);
@@ -187,10 +187,10 @@ namespace meta_hpp
[[nodiscard]] const std::string& get_name() const noexcept;
template < typename... Args >
value invoke(Args&&... args) const;
uvalue invoke(Args&&... args) const;
template < typename... Args >
value operator()(Args&&... args) const;
uvalue operator()(Args&&... args) const;
template < typename... Args >
[[nodiscard]] bool is_invocable_with() const noexcept;
@@ -218,13 +218,13 @@ namespace meta_hpp
[[nodiscard]] const std::string& get_name() const noexcept;
template < typename Instance >
[[nodiscard]] value get(Instance&& instance) const;
[[nodiscard]] uvalue get(Instance&& instance) const;
template < typename Instance, typename Value >
void set(Instance&& instance, Value&& value) const;
template < typename Instance >
[[nodiscard]] value operator()(Instance&& instance) const;
[[nodiscard]] uvalue operator()(Instance&& instance) const;
template < typename Instance, typename Value >
void operator()(Instance&& instance, Value&& value) const;
@@ -258,10 +258,10 @@ namespace meta_hpp
[[nodiscard]] const std::string& get_name() const noexcept;
template < typename Instance, typename... Args >
value invoke(Instance&& instance, Args&&... args) const;
uvalue invoke(Instance&& instance, Args&&... args) const;
template < typename Instance, typename... Args >
value operator()(Instance&& instance, Args&&... args) const;
uvalue operator()(Instance&& instance, Args&&... args) const;
template < typename Instance, typename... Args >
[[nodiscard]] bool is_invocable_with() const noexcept;
@@ -337,12 +337,12 @@ namespace meta_hpp
[[nodiscard]] const pointer_type& get_type() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
[[nodiscard]] value get() const;
[[nodiscard]] uvalue get() const;
template < typename Value >
void set(Value&& value) const;
[[nodiscard]] value operator()() const;
[[nodiscard]] uvalue operator()() const;
template < typename Value >
void operator()(Value&& value) const;
@@ -395,8 +395,8 @@ namespace meta_hpp
namespace meta_hpp::detail
{
struct ctor_state final {
using invoke_impl = fixed_function<value(std::span<const arg>)>;
using is_invocable_with_impl = fixed_function<bool(std::span<const arg_base>)>;
using invoke_impl = fixed_function<uvalue(std::span<const uarg>)>;
using is_invocable_with_impl = fixed_function<bool(std::span<const uarg_base>)>;
ctor_index index;
invoke_impl invoke;
@@ -409,8 +409,8 @@ namespace meta_hpp::detail
};
struct dtor_state final {
using invoke_impl = fixed_function<void(const arg&)>;
using is_invocable_with_impl = fixed_function<bool(const arg_base&)>;
using invoke_impl = fixed_function<void(const uarg&)>;
using is_invocable_with_impl = fixed_function<bool(const uarg_base&)>;
dtor_index index;
invoke_impl invoke;
@@ -422,16 +422,16 @@ namespace meta_hpp::detail
struct evalue_state final {
evalue_index index;
value enum_value;
value underlying_value;
uvalue enum_value;
uvalue underlying_value;
template < enum_kind Enum >
[[nodiscard]] static evalue_state_ptr make(std::string name, Enum evalue);
};
struct function_state final {
using invoke_impl = fixed_function<value(std::span<const arg>)>;
using is_invocable_with_impl = fixed_function<bool(std::span<const arg_base>)>;
using invoke_impl = fixed_function<uvalue(std::span<const uarg>)>;
using is_invocable_with_impl = fixed_function<bool(std::span<const uarg_base>)>;
function_index index;
invoke_impl invoke;
@@ -444,11 +444,11 @@ namespace meta_hpp::detail
};
struct member_state final {
using getter_impl = fixed_function<value(const inst&)>;
using setter_impl = fixed_function<void(const inst&, const arg&)>;
using getter_impl = fixed_function<uvalue(const uinst&)>;
using setter_impl = fixed_function<void(const uinst&, const uarg&)>;
using is_gettable_with_impl = fixed_function<bool(const inst_base&)>;
using is_settable_with_impl = fixed_function<bool(const inst_base&, const arg_base&)>;
using is_gettable_with_impl = fixed_function<bool(const uinst_base&)>;
using is_settable_with_impl = fixed_function<bool(const uinst_base&, const uarg_base&)>;
member_index index;
getter_impl getter;
@@ -461,8 +461,8 @@ namespace meta_hpp::detail
};
struct method_state final {
using invoke_impl = fixed_function<value(const inst&, std::span<const arg>)>;
using is_invocable_with_impl = fixed_function<bool(const inst_base&, std::span<const arg_base>)>;
using invoke_impl = fixed_function<uvalue(const uinst&, std::span<const uarg>)>;
using is_invocable_with_impl = fixed_function<bool(const uinst_base&, std::span<const uarg_base>)>;
method_index index;
invoke_impl invoke;
@@ -495,9 +495,9 @@ namespace meta_hpp::detail
};
struct variable_state final {
using getter_impl = fixed_function<value()>;
using setter_impl = fixed_function<void(const arg&)>;
using is_settable_with_impl = fixed_function<bool(const arg_base&)>;
using getter_impl = fixed_function<uvalue()>;
using setter_impl = fixed_function<void(const uarg&)>;
using is_settable_with_impl = fixed_function<bool(const uarg_base&)>;
variable_index index;
getter_impl getter;

View File

@@ -10,12 +10,12 @@
#include "../meta_states.hpp"
#include "../meta_types/ctor_type.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail
{
template < ctor_policy_kind Policy, class_kind Class, typename... Args >
value raw_ctor_invoke(std::span<const arg> args) {
uvalue raw_ctor_invoke(std::span<const uarg> args) {
using ct = ctor_traits<Class, Args...>;
using class_type = typename ct::class_type;
using argument_types = typename ct::argument_types;
@@ -39,30 +39,30 @@ namespace meta_hpp::detail
return std::invoke([
args
// NOLINTNEXTLINE(readability-named-parameter)
]<std::size_t... Is>(std::index_sequence<Is...>) -> value {
]<std::size_t... Is>(std::index_sequence<Is...>) -> uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
throw_exception_with("an attempt to call a constructor with incorrect argument types");
}
if constexpr ( as_object ) {
class_type return_value{args[Is].cast<type_list_at_t<Is, argument_types>>()...};
return value{std::move(return_value)};
return uvalue{std::move(return_value)};
}
if constexpr ( as_raw_ptr ) {
auto return_value{std::make_unique<class_type>(args[Is].cast<type_list_at_t<Is, argument_types>>()...)};
return value{return_value.release()};
return uvalue{return_value.release()};
}
if constexpr ( as_shared_ptr ) {
auto return_value{std::make_shared<class_type>(args[Is].cast<type_list_at_t<Is, argument_types>>()...)};
return value{std::move(return_value)};
return uvalue{std::move(return_value)};
}
}, std::make_index_sequence<ct::arity>());
}
template < class_kind Class, typename... Args >
bool raw_ctor_is_invocable_with(std::span<const arg_base> args) {
bool raw_ctor_is_invocable_with(std::span<const uarg_base> args) {
using ct = ctor_traits<Class, Args...>;
using argument_types = typename ct::argument_types;
@@ -143,10 +143,10 @@ namespace meta_hpp
}
template < typename... Args >
value ctor::invoke(Args&&... args) const {
uvalue ctor::invoke(Args&&... args) const {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return state_->invoke(vargs);
} else {
return state_->invoke({});
@@ -154,7 +154,7 @@ namespace meta_hpp
}
template < typename... Args >
value ctor::operator()(Args&&... args) const {
uvalue ctor::operator()(Args&&... args) const {
return invoke(std::forward<Args>(args)...);
}
@@ -162,7 +162,7 @@ namespace meta_hpp
bool ctor::is_invocable_with() const noexcept {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
return state_->is_invocable_with(vargs);
} else {
return state_->is_invocable_with({});
@@ -173,7 +173,7 @@ namespace meta_hpp
bool ctor::is_invocable_with(Args&&... args) const noexcept {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{std::forward<Args>(args)}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
return state_->is_invocable_with(vargs);
} else {
return state_->is_invocable_with({});

View File

@@ -10,12 +10,12 @@
#include "../meta_states.hpp"
#include "../meta_types/dtor_type.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail
{
template < class_kind Class >
void raw_dtor_invoke(const arg& ptr) {
void raw_dtor_invoke(const uarg& ptr) {
using dt = dtor_traits<Class>;
using class_type = typename dt::class_type;
@@ -30,7 +30,7 @@ namespace meta_hpp::detail
}
template < class_kind Class >
bool raw_dtor_is_invocable_with(const arg_base& ptr) {
bool raw_dtor_is_invocable_with(const uarg_base& ptr) {
using dt = dtor_traits<Class>;
using class_type = typename dt::class_type;
@@ -87,7 +87,7 @@ namespace meta_hpp
template < typename Arg >
void dtor::invoke(Arg&& ptr) const {
using namespace detail;
const arg varg{std::forward<Arg>(ptr)};
const uarg varg{std::forward<Arg>(ptr)};
state_->invoke(varg);
}
@@ -99,14 +99,14 @@ namespace meta_hpp
template < typename Arg >
bool dtor::is_invocable_with() const noexcept {
using namespace detail;
const arg_base varg{type_list<Arg>{}};
const uarg_base varg{type_list<Arg>{}};
return state_->is_invocable_with(varg);
}
template < typename Arg >
bool dtor::is_invocable_with(Arg&& ptr) const noexcept {
using namespace detail;
const arg_base varg{std::forward<Arg>(ptr)};
const uarg_base varg{std::forward<Arg>(ptr)};
return state_->is_invocable_with(varg);
}
}

View File

@@ -17,8 +17,8 @@ namespace meta_hpp::detail
evalue_state_ptr evalue_state::make(std::string name, Enum evalue) {
return std::make_shared<evalue_state>(evalue_state{
.index{evalue_index::make<Enum>(std::move(name))},
.enum_value{value{evalue}},
.underlying_value{value{stdex::to_underlying(evalue)}},
.enum_value{uvalue{evalue}},
.underlying_value{uvalue{stdex::to_underlying(evalue)}},
});
}
}
@@ -48,11 +48,11 @@ namespace meta_hpp
return state_->index.get_name();
}
inline const value& evalue::get_value() const noexcept {
inline const uvalue& evalue::get_value() const noexcept {
return state_->enum_value;
}
inline const value& evalue::get_underlying_value() const noexcept {
inline const uvalue& evalue::get_underlying_value() const noexcept {
return state_->underlying_value;
}
}

View File

@@ -10,12 +10,12 @@
#include "../meta_states.hpp"
#include "../meta_types/function_type.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail
{
template < function_policy_kind Policy, function_kind Function >
value raw_function_invoke(const Function& function, std::span<const arg> args) {
uvalue raw_function_invoke(const Function& function, std::span<const uarg> args) {
using ft = function_traits<Function>;
using return_type = typename ft::return_type;
using argument_types = typename ft::argument_types;
@@ -41,7 +41,7 @@ namespace meta_hpp::detail
return std::invoke([
&function, args
// NOLINTNEXTLINE(readability-named-parameter)
]<std::size_t... Is>(std::index_sequence<Is...>) -> value {
]<std::size_t... Is>(std::index_sequence<Is...>) -> uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
throw_exception_with("an attempt to call a function with incorrect argument types");
}
@@ -50,23 +50,23 @@ namespace meta_hpp::detail
std::ignore = std::invoke(
function,
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return value{};
return uvalue{};
} else {
return_type&& return_value = std::invoke(
function,
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
if constexpr ( ref_as_ptr ) {
return value{std::addressof(return_value)};
return uvalue{std::addressof(return_value)};
} else {
return value{std::forward<decltype(return_value)>(return_value)};
return uvalue{std::forward<decltype(return_value)>(return_value)};
}
}
}, std::make_index_sequence<ft::arity>());
}
template < function_kind Function >
bool raw_function_is_invocable_with(std::span<const arg_base> args) {
bool raw_function_is_invocable_with(std::span<const uarg_base> args) {
using ft = function_traits<Function>;
using argument_types = typename ft::argument_types;
@@ -85,7 +85,7 @@ namespace meta_hpp::detail
{
template < function_policy_kind Policy, function_kind Function >
function_state::invoke_impl make_function_invoke(Function function) {
return [function = std::move(function)](std::span<const arg> args){
return [function = std::move(function)](std::span<const uarg> args){
return raw_function_invoke<Policy>(function, args);
};
}
@@ -153,10 +153,10 @@ namespace meta_hpp
}
template < typename... Args >
value function::invoke(Args&&... args) const {
uvalue function::invoke(Args&&... args) const {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return state_->invoke(vargs);
} else {
return state_->invoke({});
@@ -164,7 +164,7 @@ namespace meta_hpp
}
template < typename... Args >
value function::operator()(Args&&... args) const {
uvalue function::operator()(Args&&... args) const {
return invoke(std::forward<Args>(args)...);
}
@@ -172,7 +172,7 @@ namespace meta_hpp
bool function::is_invocable_with() const noexcept {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
return state_->is_invocable_with(vargs);
} else {
return state_->is_invocable_with({});
@@ -183,7 +183,7 @@ namespace meta_hpp
bool function::is_invocable_with(Args&&... args) const noexcept {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{std::forward<Args>(args)}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
return state_->is_invocable_with(vargs);
} else {
return state_->is_invocable_with({});

View File

@@ -10,13 +10,13 @@
#include "../meta_states.hpp"
#include "../meta_types/member_type.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/inst.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
#include "../meta_detail/value_utilities/uinst.hpp"
namespace meta_hpp::detail
{
template < member_policy_kind Policy, member_kind Member >
value raw_member_getter(const Member& member, const inst& inst) {
uvalue raw_member_getter(const Member& member, const uinst& inst) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
@@ -41,35 +41,35 @@ namespace meta_hpp::detail
auto&& return_value = std::invoke(member, inst.cast<const class_type>());
if constexpr ( as_copy ) {
return value{std::forward<decltype(return_value)>(return_value)};
return uvalue{std::forward<decltype(return_value)>(return_value)};
}
if constexpr ( as_ptr ) {
return value{std::addressof(return_value)};
return uvalue{std::addressof(return_value)};
}
if constexpr ( as_ref_wrap ) {
return value{std::ref(return_value)};
return uvalue{std::ref(return_value)};
}
} else {
auto&& return_value = std::invoke(member, inst.cast<class_type>());
if constexpr ( as_copy ) {
return value{std::forward<decltype(return_value)>(return_value)};
return uvalue{std::forward<decltype(return_value)>(return_value)};
}
if constexpr ( as_ptr ) {
return value{std::addressof(return_value)};
return uvalue{std::addressof(return_value)};
}
if constexpr ( as_ref_wrap ) {
return value{std::ref(return_value)};
return uvalue{std::ref(return_value)};
}
}
}
template < member_kind Member >
bool raw_member_is_gettable_with(const inst_base& inst) {
bool raw_member_is_gettable_with(const uinst_base& inst) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
@@ -80,7 +80,7 @@ namespace meta_hpp::detail
namespace meta_hpp::detail
{
template < member_kind Member >
void raw_member_setter([[maybe_unused]] const Member& member, const inst& inst, const arg& arg) {
void raw_member_setter([[maybe_unused]] const Member& member, const uinst& inst, const uarg& arg) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
@@ -105,7 +105,7 @@ namespace meta_hpp::detail
}
template < member_kind Member >
bool raw_member_is_settable_with(const inst_base& inst, const arg_base& arg) {
bool raw_member_is_settable_with(const uinst_base& inst, const uarg_base& arg) {
using mt = member_traits<Member>;
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
@@ -121,7 +121,7 @@ namespace meta_hpp::detail
{
template < member_policy_kind Policy, member_kind Member >
member_state::getter_impl make_member_getter(Member member) {
return [member = std::move(member)](const inst& inst){
return [member = std::move(member)](const uinst& inst){
return raw_member_getter<Policy>(member, inst);
};
}
@@ -133,7 +133,7 @@ namespace meta_hpp::detail
template < member_kind Member >
member_state::setter_impl make_member_setter(Member member) {
return [member = std::move(member)](const inst& inst, const arg& arg){
return [member = std::move(member)](const uinst& inst, const uarg& arg){
return raw_member_setter(member, inst, arg);
};
}
@@ -184,22 +184,22 @@ namespace meta_hpp
}
template < typename Instance >
value member::get(Instance&& instance) const {
uvalue member::get(Instance&& instance) const {
using namespace detail;
const inst vinst{std::forward<Instance>(instance)};
const uinst vinst{std::forward<Instance>(instance)};
return state_->getter(vinst);
}
template < typename Instance, typename Value >
void member::set(Instance&& instance, Value&& value) const {
using namespace detail;
const inst vinst{std::forward<Instance>(instance)};
const arg vvalue{std::forward<Value>(value)};
const uinst vinst{std::forward<Instance>(instance)};
const uarg vvalue{std::forward<Value>(value)};
state_->setter(vinst, vvalue);
}
template < typename Instance >
value member::operator()(Instance&& instance) const {
uvalue member::operator()(Instance&& instance) const {
return get(std::forward<Instance>(instance));
}
@@ -211,30 +211,30 @@ namespace meta_hpp
template < typename Instance >
[[nodiscard]] bool member::is_gettable_with() const noexcept {
using namespace detail;
const inst_base vinst{type_list<Instance>{}};
const uinst_base vinst{type_list<Instance>{}};
return state_->is_gettable_with(vinst);
}
template < typename Instance >
[[nodiscard]] bool member::is_gettable_with(Instance&& instance) const noexcept {
using namespace detail;
const inst_base vinst{std::forward<Instance>(instance)};
const uinst_base vinst{std::forward<Instance>(instance)};
return state_->is_gettable_with(vinst);
}
template < typename Instance, typename Value >
[[nodiscard]] bool member::is_settable_with() const noexcept {
using namespace detail;
const inst_base vinst{type_list<Instance>{}};
const arg_base vvalue{type_list<Value>{}};
const uinst_base vinst{type_list<Instance>{}};
const uarg_base vvalue{type_list<Value>{}};
return state_->is_settable_with(vinst, vvalue);
}
template < typename Instance, typename Value >
[[nodiscard]] bool member::is_settable_with(Instance&& instance, Value&& value) const noexcept {
using namespace detail;
const inst_base vinst{std::forward<Instance>(instance)};
const arg_base vvalue{std::forward<Value>(value)};
const uinst_base vinst{std::forward<Instance>(instance)};
const uarg_base vvalue{std::forward<Value>(value)};
return state_->is_settable_with(vinst, vvalue);
}
}

View File

@@ -10,13 +10,13 @@
#include "../meta_states.hpp"
#include "../meta_types/method_type.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/inst.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
#include "../meta_detail/value_utilities/uinst.hpp"
namespace meta_hpp::detail
{
template < method_policy_kind Policy, method_kind Method >
value raw_method_invoke(const Method& method, const inst& inst, std::span<const arg> args) {
uvalue raw_method_invoke(const Method& method, const uinst& inst, std::span<const uarg> args) {
using mt = method_traits<Method>;
using return_type = typename mt::return_type;
using qualified_type = typename mt::qualified_type;
@@ -47,7 +47,7 @@ namespace meta_hpp::detail
return std::invoke([
&method, &inst, args
// NOLINTNEXTLINE(readability-named-parameter)
]<std::size_t... Is>(std::index_sequence<Is...>) -> value {
]<std::size_t... Is>(std::index_sequence<Is...>) -> uvalue {
if ( !(... && args[Is].can_cast_to<type_list_at_t<Is, argument_types>>()) ) {
throw_exception_with("an attempt to call a method with incorrect argument types");
}
@@ -57,7 +57,7 @@ namespace meta_hpp::detail
method,
inst.cast<qualified_type>(),
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
return value{};
return uvalue{};
} else {
return_type&& return_value = std::invoke(
method,
@@ -65,16 +65,16 @@ namespace meta_hpp::detail
args[Is].cast<type_list_at_t<Is, argument_types>>()...);
if constexpr ( ref_as_ptr ) {
return value{std::addressof(return_value)};
return uvalue{std::addressof(return_value)};
} else {
return value{std::forward<decltype(return_value)>(return_value)};
return uvalue{std::forward<decltype(return_value)>(return_value)};
}
}
}, std::make_index_sequence<mt::arity>());
}
template < method_kind Method >
bool raw_method_is_invocable_with(const inst_base& inst, std::span<const arg_base> args) {
bool raw_method_is_invocable_with(const uinst_base& inst, std::span<const uarg_base> args) {
using mt = method_traits<Method>;
using qualified_type = typename mt::qualified_type;
using argument_types = typename mt::argument_types;
@@ -98,7 +98,7 @@ namespace meta_hpp::detail
{
template < method_policy_kind Policy, method_kind Method >
method_state::invoke_impl make_method_invoke(Method method) {
return [method = std::move(method)](const inst& inst, std::span<const arg> args){
return [method = std::move(method)](const uinst& inst, std::span<const uarg> args){
return raw_method_invoke<Policy>(method, inst, args);
};
}
@@ -166,11 +166,11 @@ namespace meta_hpp
}
template < typename Instance, typename... Args >
value method::invoke(Instance&& instance, Args&&... args) const {
uvalue method::invoke(Instance&& instance, Args&&... args) const {
using namespace detail;
const inst vinst{std::forward<Instance>(instance)};
const uinst vinst{std::forward<Instance>(instance)};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return state_->invoke(vinst, vargs);
} else {
return state_->invoke(vinst, {});
@@ -178,16 +178,16 @@ namespace meta_hpp
}
template < typename Instance, typename... Args >
value method::operator()(Instance&& instance, Args&&... args) const {
uvalue method::operator()(Instance&& instance, Args&&... args) const {
return invoke(std::forward<Instance>(instance), std::forward<Args>(args)...);
}
template < typename Instance, typename... Args >
bool method::is_invocable_with() const noexcept {
using namespace detail;
const inst_base vinst{type_list<Instance>{}};
const uinst_base vinst{type_list<Instance>{}};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
return state_->is_invocable_with(vinst, vargs);
} else {
return state_->is_invocable_with(vinst, {});
@@ -197,9 +197,9 @@ namespace meta_hpp
template < typename Instance, typename... Args >
bool method::is_invocable_with(Instance&& instance, Args&&... args) const noexcept {
using namespace detail;
const inst_base vinst{std::forward<Instance>(instance)};
const uinst_base vinst{std::forward<Instance>(instance)};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{std::forward<Args>(args)}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
return state_->is_invocable_with(vinst, vargs);
} else {
return state_->is_invocable_with(vinst, {});

View File

@@ -10,12 +10,12 @@
#include "../meta_states.hpp"
#include "../meta_types/pointer_type.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail
{
template < variable_policy_kind Policy, pointer_kind Pointer >
value raw_variable_getter(const Pointer& pointer) {
uvalue raw_variable_getter(const Pointer& pointer) {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
@@ -34,20 +34,20 @@ namespace meta_hpp::detail
auto&& return_value = *pointer;
if constexpr ( as_copy ) {
return value{std::forward<decltype(return_value)>(return_value)};
return uvalue{std::forward<decltype(return_value)>(return_value)};
}
if constexpr ( as_ptr ) {
return value{std::addressof(return_value)};
return uvalue{std::addressof(return_value)};
}
if constexpr ( as_ref_wrap) {
return value{std::ref(return_value)};
return uvalue{std::ref(return_value)};
}
}
template < pointer_kind Pointer >
void raw_variable_setter([[maybe_unused]] const Pointer& pointer, const arg& arg) {
void raw_variable_setter([[maybe_unused]] const Pointer& pointer, const uarg& arg) {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
@@ -62,7 +62,7 @@ namespace meta_hpp::detail
}
template < pointer_kind Pointer >
bool raw_variable_is_settable_with(const arg_base& arg) {
bool raw_variable_is_settable_with(const uarg_base& arg) {
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
@@ -82,7 +82,7 @@ namespace meta_hpp::detail
template < pointer_kind Pointer >
variable_state::setter_impl make_variable_setter(Pointer pointer) {
return [pointer = std::move(pointer)](const arg& arg){
return [pointer = std::move(pointer)](const uarg& arg){
return raw_variable_setter(pointer, arg);
};
}
@@ -131,18 +131,18 @@ namespace meta_hpp
return state_->index.get_name();
}
inline value variable::get() const {
inline uvalue variable::get() const {
return state_->getter();
}
template < typename Value >
void variable::set(Value&& value) const {
using namespace detail;
const arg vvalue{std::forward<Value>(value)};
const uarg vvalue{std::forward<Value>(value)};
state_->setter(vvalue);
}
inline value variable::operator()() const {
inline uvalue variable::operator()() const {
return get();
}
@@ -154,14 +154,14 @@ namespace meta_hpp
template < typename Value >
bool variable::is_settable_with() const noexcept {
using namespace detail;
const arg_base vvalue{type_list<Value>{}};
const uarg_base vvalue{type_list<Value>{}};
return state_->is_settable_with(vvalue);
}
template < typename Value >
bool variable::is_settable_with(Value&& value) const noexcept {
using namespace detail;
const arg vvalue{std::forward<Value>(value)};
const uarg vvalue{std::forward<Value>(value)};
return state_->is_settable_with(vvalue);
}
}

View File

@@ -160,10 +160,10 @@ namespace meta_hpp
[[nodiscard]] const variable_map& get_variables() const noexcept;
template < typename... Args >
[[nodiscard]] value create(Args&&... args) const;
[[nodiscard]] uvalue create(Args&&... args) const;
template < typename... Args >
[[nodiscard]] value operator()(Args&&... args) const;
[[nodiscard]] uvalue operator()(Args&&... args) const;
template < typename Arg >
bool destroy(Arg&& ptr) const;
@@ -262,7 +262,7 @@ namespace meta_hpp
template < typename Value >
[[nodiscard]] std::string_view value_to_name(Value&& value) const noexcept;
[[nodiscard]] value name_to_value(std::string_view name) const noexcept;
[[nodiscard]] uvalue name_to_value(std::string_view name) const noexcept;
private:
detail::enum_type_data_ptr data_;
friend auto detail::type_access<enum_type>(const enum_type&);

View File

@@ -98,17 +98,17 @@ namespace meta_hpp
}
template < typename... Args >
value class_type::create(Args&&... args) const {
uvalue class_type::create(Args&&... args) const {
for ( auto&& ctor : data_->ctors ) {
if ( ctor.second.is_invocable_with(std::forward<Args>(args)...) ) {
return ctor.second.invoke(std::forward<Args>(args)...);
}
}
return value{};
return uvalue{};
}
template < typename... Args >
value class_type::operator()(Args&&... args) const {
uvalue class_type::operator()(Args&&... args) const {
return create(std::forward<Args>(args)...);
}

View File

@@ -13,7 +13,7 @@
#include "../meta_detail/type_registry.hpp"
#include "../meta_detail/type_traits/enum_traits.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail
{
@@ -68,7 +68,7 @@ namespace meta_hpp
template < typename Value >
std::string_view enum_type::value_to_name(Value&& value) const noexcept {
const detail::arg value_arg{std::forward<Value>(value)};
const detail::uarg value_arg{std::forward<Value>(value)};
if ( value_arg.get_raw_type() != *this ) {
return std::string_view{};
@@ -83,11 +83,11 @@ namespace meta_hpp
return std::string_view{};
}
inline value enum_type::name_to_value(std::string_view name) const noexcept {
inline uvalue enum_type::name_to_value(std::string_view name) const noexcept {
if ( const evalue value = get_evalue(name); value ) {
return value.get_value();
}
return value{};
return uvalue{};
}
}

View File

@@ -12,7 +12,7 @@
namespace meta_hpp::detail
{
template < typename T >
inline constexpr bool is_value_kind_v = std::is_same_v<T, value>;
inline constexpr bool is_value_kind_v = std::is_same_v<T, uvalue>;
template < typename T >
concept value_kind = is_value_kind_v<T>;
@@ -26,30 +26,30 @@ namespace meta_hpp::detail
namespace meta_hpp
{
class value final {
class uvalue final {
public:
value() = default;
~value();
uvalue() = default;
~uvalue();
value(value&& other) noexcept;
value(const value& other);
uvalue(uvalue&& other) noexcept;
uvalue(const uvalue& other);
value& operator=(value&& other) noexcept;
value& operator=(const value& other);
uvalue& operator=(uvalue&& other) noexcept;
uvalue& operator=(const uvalue& other);
template < detail::decay_non_value_kind T >
requires stdex::copy_constructible<std::decay_t<T>>
explicit value(T&& val);
explicit uvalue(T&& val);
template < detail::decay_non_value_kind T >
requires stdex::copy_constructible<std::decay_t<T>>
value& operator=(T&& val);
uvalue& operator=(T&& val);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
void reset();
void swap(value& other) noexcept;
void swap(uvalue& other) noexcept;
[[nodiscard]] const any_type& get_type() const noexcept;
@@ -57,8 +57,8 @@ namespace meta_hpp
[[nodiscard]] const void* data() const noexcept;
[[nodiscard]] const void* cdata() const noexcept;
[[nodiscard]] value operator*() const;
[[nodiscard]] value operator[](std::size_t index) const;
[[nodiscard]] uvalue operator*() const;
[[nodiscard]] uvalue operator[](std::size_t index) const;
template < typename T >
[[nodiscard]] std::decay_t<T>& cast() &;
@@ -78,10 +78,10 @@ namespace meta_hpp
template < typename T >
[[nodiscard]] const std::decay_t<T>* try_cast() const noexcept;
friend bool operator<(const value& l, const value& r);
friend bool operator==(const value& l, const value& r);
friend std::istream& operator>>(std::istream& is, value& v);
friend std::ostream& operator<<(std::ostream& os, const value& v);
friend bool operator<(const uvalue& l, const uvalue& r);
friend bool operator==(const uvalue& l, const uvalue& r);
friend std::istream& operator>>(std::istream& is, uvalue& v);
friend std::ostream& operator<<(std::ostream& os, const uvalue& v);
private:
struct vtable_t;
vtable_t* vtable_{};
@@ -91,7 +91,7 @@ namespace meta_hpp
storage_u storage_{};
};
inline void swap(value& l, value& r) noexcept {
inline void swap(uvalue& l, uvalue& r) noexcept {
l.swap(r);
}
}

View File

@@ -20,24 +20,24 @@
namespace meta_hpp
{
struct value::vtable_t final {
struct uvalue::vtable_t final {
const any_type type;
void* (*const data)(storage_u& from) noexcept;
const void* (*const cdata)(const storage_u& from) noexcept;
void (*const move)(value& from, value& to) noexcept;
void (*const copy)(const value& from, value& to);
void (*const destroy)(value& self) noexcept;
void (*const move)(uvalue& from, uvalue& to) noexcept;
void (*const copy)(const uvalue& from, uvalue& to);
void (*const destroy)(uvalue& self) noexcept;
value (*const deref)(const value& from);
value (*const index)(const value& from, std::size_t);
uvalue (*const deref)(const uvalue& from);
uvalue (*const index)(const uvalue& from, std::size_t);
bool (*const less)(const value&, const value&);
bool (*const equals)(const value&, const value&);
bool (*const less)(const uvalue&, const uvalue&);
bool (*const equals)(const uvalue&, const uvalue&);
std::istream& (*const istream)(std::istream&, value&);
std::ostream& (*const ostream)(std::ostream&, const value&);
std::istream& (*const istream)(std::istream&, uvalue&);
std::ostream& (*const ostream)(std::ostream&, const uvalue&);
template < typename T >
static T* buffer_cast(buffer_t& buffer) noexcept {
@@ -70,7 +70,7 @@ namespace meta_hpp
}
template < typename T >
static void construct(value& dst, T&& val) {
static void construct(uvalue& dst, T&& val) {
using Tp = std::decay_t<T>;
constexpr bool in_buffer =
@@ -88,19 +88,19 @@ namespace meta_hpp
dst.vtable_ = vtable_t::get<Tp>();
}
static void swap(value& l, value& r) noexcept {
static void swap(uvalue& l, uvalue& r) noexcept {
if ( (&l == &r) || (!l && !r) ) {
return;
}
if ( l && r ) {
if ( std::holds_alternative<buffer_t>(l.storage_) ) {
value temp;
uvalue temp;
r.vtable_->move(r, temp);
l.vtable_->move(l, r);
temp.vtable_->move(temp, l);
} else {
value temp;
uvalue temp;
l.vtable_->move(l, temp);
r.vtable_->move(r, l);
temp.vtable_->move(temp, r);
@@ -128,7 +128,7 @@ namespace meta_hpp
return storage_cast<Tp>(from);
},
.move = [](value& from, value& to) noexcept {
.move = [](uvalue& from, uvalue& to) noexcept {
assert(from && !to);
std::visit(detail::overloaded {
@@ -148,7 +148,7 @@ namespace meta_hpp
from.vtable_ = nullptr;
},
.copy = [](const value& from, value& to){
.copy = [](const uvalue& from, uvalue& to){
assert(from && !to);
std::visit(detail::overloaded {
@@ -166,7 +166,7 @@ namespace meta_hpp
to.vtable_ = from.vtable_;
},
.destroy = [](value& self) noexcept {
.destroy = [](uvalue& self) noexcept {
assert(self);
std::visit(detail::overloaded {
@@ -184,7 +184,7 @@ namespace meta_hpp
self.vtable_ = nullptr;
},
.deref = +[]([[maybe_unused]] const value& v) -> value {
.deref = +[]([[maybe_unused]] const uvalue& v) -> uvalue {
if constexpr ( detail::has_deref_traits<Tp> ) {
return detail::deref_traits<Tp>{}(v.cast<Tp>());
} else {
@@ -192,7 +192,7 @@ namespace meta_hpp
}
},
.index = +[]([[maybe_unused]] const value& v, [[maybe_unused]] std::size_t i) -> value {
.index = +[]([[maybe_unused]] const uvalue& v, [[maybe_unused]] std::size_t i) -> uvalue {
if constexpr ( detail::has_index_traits<Tp> ) {
return detail::index_traits<Tp>{}(v.cast<Tp>(), i);
} else {
@@ -200,7 +200,7 @@ namespace meta_hpp
}
},
.less = +[]([[maybe_unused]] const value& l, [[maybe_unused]] const value& r) -> bool {
.less = +[]([[maybe_unused]] const uvalue& l, [[maybe_unused]] const uvalue& r) -> bool {
if constexpr ( detail::has_less_traits<Tp> ) {
return detail::less_traits<Tp>{}(l.cast<Tp>(), r.cast<Tp>());
} else {
@@ -208,7 +208,7 @@ namespace meta_hpp
}
},
.equals = +[]([[maybe_unused]] const value& l, [[maybe_unused]] const value& r) -> bool {
.equals = +[]([[maybe_unused]] const uvalue& l, [[maybe_unused]] const uvalue& r) -> bool {
if constexpr ( detail::has_equals_traits<Tp> ) {
return detail::equals_traits<Tp>{}(l.cast<Tp>(), r.cast<Tp>());
} else {
@@ -216,7 +216,7 @@ namespace meta_hpp
}
},
.istream = +[]([[maybe_unused]] std::istream& is, [[maybe_unused]] value& v) -> std::istream& {
.istream = +[]([[maybe_unused]] std::istream& is, [[maybe_unused]] uvalue& v) -> std::istream& {
if constexpr ( detail::has_istream_traits<Tp> ) {
return detail::istream_traits<Tp>{}(is, v.cast<Tp>());
} else {
@@ -224,7 +224,7 @@ namespace meta_hpp
}
},
.ostream = +[]([[maybe_unused]] std::ostream& os, [[maybe_unused]] const value& v) -> std::ostream& {
.ostream = +[]([[maybe_unused]] std::ostream& os, [[maybe_unused]] const uvalue& v) -> std::ostream& {
if constexpr ( detail::has_ostream_traits<Tp> ) {
return detail::ostream_traits<Tp>{}(os, v.cast<Tp>());
} else {
@@ -240,94 +240,94 @@ namespace meta_hpp
namespace meta_hpp
{
inline value::~value() {
inline uvalue::~uvalue() {
reset();
}
inline value::value(value&& other) noexcept {
inline uvalue::uvalue(uvalue&& other) noexcept {
if ( other.vtable_ != nullptr ) {
other.vtable_->move(other, *this);
}
}
inline value::value(const value& other) {
inline uvalue::uvalue(const uvalue& other) {
if ( other.vtable_ != nullptr ) {
other.vtable_->copy(other, *this);
}
}
inline value& value::operator=(value&& other) noexcept {
inline uvalue& uvalue::operator=(uvalue&& other) noexcept {
if ( this != &other ) {
value{std::move(other)}.swap(*this);
uvalue{std::move(other)}.swap(*this);
}
return *this;
}
inline value& value::operator=(const value& other) {
inline uvalue& uvalue::operator=(const uvalue& other) {
if ( this != &other ) {
value{other}.swap(*this);
uvalue{other}.swap(*this);
}
return *this;
}
template < detail::decay_non_value_kind T >
requires stdex::copy_constructible<std::decay_t<T>>
value::value(T&& val) {
uvalue::uvalue(T&& val) {
vtable_t::construct(*this, std::forward<T>(val));
}
template < detail::decay_non_value_kind T >
requires stdex::copy_constructible<std::decay_t<T>>
value& value::operator=(T&& val) {
value{std::forward<T>(val)}.swap(*this);
uvalue& uvalue::operator=(T&& val) {
uvalue{std::forward<T>(val)}.swap(*this);
return *this;
}
inline bool value::is_valid() const noexcept {
inline bool uvalue::is_valid() const noexcept {
return vtable_ != nullptr;
}
inline value::operator bool() const noexcept {
inline uvalue::operator bool() const noexcept {
return is_valid();
}
inline void value::reset() {
inline void uvalue::reset() {
if ( vtable_ != nullptr ) {
vtable_->destroy(*this);
}
}
inline void value::swap(value& other) noexcept {
inline void uvalue::swap(uvalue& other) noexcept {
vtable_t::swap(*this, other);
}
inline const any_type& value::get_type() const noexcept {
inline const any_type& uvalue::get_type() const noexcept {
static any_type void_type = detail::resolve_type<void>();
return vtable_ != nullptr ? vtable_->type : void_type;
}
inline void* value::data() noexcept {
inline void* uvalue::data() noexcept {
return vtable_ != nullptr ? vtable_->data(storage_) : nullptr;
}
inline const void* value::data() const noexcept {
inline const void* uvalue::data() const noexcept {
return vtable_ != nullptr ? vtable_->cdata(storage_) : nullptr;
}
inline const void* value::cdata() const noexcept {
inline const void* uvalue::cdata() const noexcept {
return vtable_ != nullptr ? vtable_->cdata(storage_) : nullptr;
}
inline value value::operator*() const {
return vtable_ != nullptr ? vtable_->deref(*this) : value{};
inline uvalue uvalue::operator*() const {
return vtable_ != nullptr ? vtable_->deref(*this) : uvalue{};
}
inline value value::operator[](std::size_t index) const {
return vtable_ != nullptr ? vtable_->index(*this, index) : value{};
inline uvalue uvalue::operator[](std::size_t index) const {
return vtable_ != nullptr ? vtable_->index(*this, index) : uvalue{};
}
template < typename T >
std::decay_t<T>& value::cast() & {
std::decay_t<T>& uvalue::cast() & {
using Tp = std::decay_t<T>;
if ( Tp* ptr = try_cast<Tp>() ) {
return *ptr;
@@ -336,7 +336,7 @@ namespace meta_hpp
}
template < typename T >
std::decay_t<T>&& value::cast() && {
std::decay_t<T>&& uvalue::cast() && {
using Tp = std::decay_t<T>;
if ( Tp* ptr = try_cast<Tp>() ) {
return std::move(*ptr);
@@ -345,7 +345,7 @@ namespace meta_hpp
}
template < typename T >
const std::decay_t<T>& value::cast() const & {
const std::decay_t<T>& uvalue::cast() const & {
using Tp = std::decay_t<T>;
if ( const Tp* ptr = try_cast<const Tp>() ) {
return *ptr;
@@ -354,7 +354,7 @@ namespace meta_hpp
}
template < typename T >
const std::decay_t<T>&& value::cast() const && {
const std::decay_t<T>&& uvalue::cast() const && {
using Tp = std::decay_t<T>;
if ( const Tp* ptr = try_cast<const Tp>() ) {
return std::move(*ptr);
@@ -363,7 +363,7 @@ namespace meta_hpp
}
template < typename T >
std::decay_t<T>* value::try_cast() noexcept {
std::decay_t<T>* uvalue::try_cast() noexcept {
using Tp = std::decay_t<T>;
return get_type() == detail::resolve_type<Tp>()
? vtable_t::storage_cast<Tp>(storage_)
@@ -371,7 +371,7 @@ namespace meta_hpp
}
template < typename T >
const std::decay_t<T>* value::try_cast() const noexcept {
const std::decay_t<T>* uvalue::try_cast() const noexcept {
using Tp = std::decay_t<T>;
return get_type() == detail::resolve_type<Tp>()
? vtable_t::storage_cast<Tp>(storage_)
@@ -382,7 +382,7 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename T >
[[nodiscard]] bool operator<(const value& l, const T& r) {
[[nodiscard]] bool operator<(const uvalue& l, const T& r) {
if ( !static_cast<bool>(l) ) {
return true;
}
@@ -394,7 +394,7 @@ namespace meta_hpp
}
template < typename T >
[[nodiscard]] bool operator<(const T& l, const value& r) {
[[nodiscard]] bool operator<(const T& l, const uvalue& r) {
if ( !static_cast<bool>(r) ) {
return false;
}
@@ -405,7 +405,7 @@ namespace meta_hpp
return (l_type < r_type) || (l_type == r_type && l < r.cast<T>());
}
[[nodiscard]] inline bool operator<(const value& l, const value& r) {
[[nodiscard]] inline bool operator<(const uvalue& l, const uvalue& r) {
if ( !static_cast<bool>(r) ) {
return false;
}
@@ -424,7 +424,7 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename T >
[[nodiscard]] bool operator==(const value& l, const T& r) {
[[nodiscard]] bool operator==(const uvalue& l, const T& r) {
if ( !static_cast<bool>(l) ) {
return false;
}
@@ -436,7 +436,7 @@ namespace meta_hpp
}
template < typename T >
[[nodiscard]] bool operator==(const T& l, const value& r) {
[[nodiscard]] bool operator==(const T& l, const uvalue& r) {
if ( !static_cast<bool>(r) ) {
return false;
}
@@ -447,7 +447,7 @@ namespace meta_hpp
return l_type == r_type && l == r.cast<T>();
}
[[nodiscard]] inline bool operator==(const value& l, const value& r) {
[[nodiscard]] inline bool operator==(const uvalue& l, const uvalue& r) {
if ( static_cast<bool>(l) != static_cast<bool>(r) ) {
return false;
}
@@ -465,11 +465,11 @@ namespace meta_hpp
namespace meta_hpp
{
inline std::istream& operator>>(std::istream& is, value& v) {
inline std::istream& operator>>(std::istream& is, uvalue& v) {
return v.vtable_->istream(is, v);
}
inline std::ostream& operator<<(std::ostream& os, const value& v) {
inline std::ostream& operator<<(std::ostream& os, const uvalue& v) {
return v.vtable_->ostream(os, v);
}
}

View File

@@ -10,21 +10,21 @@
#include "../meta_states.hpp"
#include "../meta_value.hpp"
#include "../meta_detail/value_utilities/arg.hpp"
#include "../meta_detail/value_utilities/inst.hpp"
#include "../meta_detail/value_utilities/uarg.hpp"
#include "../meta_detail/value_utilities/uinst.hpp"
namespace meta_hpp
{
template < typename... Args >
value invoke(const function& function, Args&&... args) {
uvalue invoke(const function& function, Args&&... args) {
return function.invoke(std::forward<Args>(args)...);
}
template < detail::function_kind Function, typename... Args >
value invoke(Function&& function, Args&&... args) {
uvalue invoke(Function&& function, Args&&... args) {
using namespace detail;
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return raw_function_invoke<function_policy::as_copy>(std::forward<Function>(function), vargs);
} else {
return raw_function_invoke<function_policy::as_copy>(std::forward<Function>(function), {});
@@ -35,14 +35,14 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename Instance >
value invoke(const member& member, Instance&& instance) {
uvalue invoke(const member& member, Instance&& instance) {
return member.get(std::forward<Instance>(instance));
}
template < detail::member_kind Member, typename Instance >
value invoke(Member&& member, Instance&& instance) {
uvalue invoke(Member&& member, Instance&& instance) {
using namespace detail;
const inst vinst{std::forward<Instance>(instance)};
const uinst vinst{std::forward<Instance>(instance)};
return raw_member_getter<member_policy::as_copy>(std::forward<Member>(member), vinst);
}
}
@@ -50,16 +50,16 @@ namespace meta_hpp
namespace meta_hpp
{
template < typename Instance, typename... Args >
value invoke(const method& method, Instance&& instance, Args&&... args) {
uvalue invoke(const method& method, Instance&& instance, Args&&... args) {
return method.invoke(std::forward<Instance>(instance), std::forward<Args>(args)...);
}
template < detail::method_kind Method, typename Instance, typename... Args >
value invoke(Method&& method, Instance&& instance, Args&&... args) {
uvalue invoke(Method&& method, Instance&& instance, Args&&... args) {
using namespace detail;
const inst vinst{std::forward<Instance>(instance)};
const uinst vinst{std::forward<Instance>(instance)};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg, sizeof...(Args)> vargs{arg{std::forward<Args>(args)}...};
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
return raw_method_invoke<method_policy::as_copy>(std::forward<Method>(method), vinst, vargs);
} else {
return raw_method_invoke<method_policy::as_copy>(std::forward<Method>(method), vinst, {});
@@ -83,7 +83,7 @@ namespace meta_hpp
bool is_invocable_with() {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
return raw_function_is_invocable_with<Function>(vargs);
} else {
return raw_function_is_invocable_with<Function>({});
@@ -94,7 +94,7 @@ namespace meta_hpp
bool is_invocable_with(Args&&... args) {
if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail;
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{std::forward<Args>(args)}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
return raw_function_is_invocable_with<Function>(vargs);
} else {
return raw_function_is_invocable_with<Function>({});
@@ -133,14 +133,14 @@ namespace meta_hpp
template < detail::member_kind Member, typename Instance >
bool is_invocable_with() {
using namespace detail;
const inst_base vinst{type_list<Instance>{}};
const uinst_base vinst{type_list<Instance>{}};
return raw_member_is_gettable_with<Member>(vinst);
}
template < detail::member_kind Member, typename Instance >
bool is_invocable_with(Instance&& instance) {
using namespace detail;
const inst_base vinst{std::forward<Instance>(instance)};
const uinst_base vinst{std::forward<Instance>(instance)};
return raw_member_is_gettable_with<Member>(vinst);
}
}
@@ -150,9 +150,9 @@ namespace meta_hpp
template < detail::method_kind Method, typename Instance, typename... Args >
bool is_invocable_with() {
using namespace detail;
const inst_base vinst{type_list<Instance>{}};
const uinst_base vinst{type_list<Instance>{}};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{type_list<Args>{}}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
return raw_method_is_invocable_with<Method>(vinst, vargs);
} else {
return raw_method_is_invocable_with<Method>(vinst, {});
@@ -162,9 +162,9 @@ namespace meta_hpp
template < detail::method_kind Method, typename Instance, typename... Args >
bool is_invocable_with(Instance&& instance, Args&&... args) {
using namespace detail;
const inst_base vinst{std::forward<Instance>(instance)};
const uinst_base vinst{std::forward<Instance>(instance)};
if constexpr ( sizeof...(Args) > 0 ) {
const std::array<arg_base, sizeof...(Args)> vargs{arg_base{std::forward<Args>(args)}...};
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
return raw_method_is_invocable_with<Method>(vinst, vargs);
} else {
return raw_method_is_invocable_with<Method>(vinst, {});