rename: ctor -> constructor, dtor -> destructor, parameter -> argument

This commit is contained in:
BlackMATov
2022-02-08 23:36:20 +07:00
parent 8e18c85823
commit 04fd737d62
38 changed files with 795 additions and 795 deletions

View File

@@ -14,24 +14,24 @@
#include "meta_binds/scope_bind.hpp" #include "meta_binds/scope_bind.hpp"
#include "meta_indices.hpp" #include "meta_indices.hpp"
#include "meta_indices/ctor_index.hpp" #include "meta_indices/argument_index.hpp"
#include "meta_indices/dtor_index.hpp" #include "meta_indices/constructor_index.hpp"
#include "meta_indices/destructor_index.hpp"
#include "meta_indices/evalue_index.hpp" #include "meta_indices/evalue_index.hpp"
#include "meta_indices/function_index.hpp" #include "meta_indices/function_index.hpp"
#include "meta_indices/member_index.hpp" #include "meta_indices/member_index.hpp"
#include "meta_indices/method_index.hpp" #include "meta_indices/method_index.hpp"
#include "meta_indices/parameter_index.hpp"
#include "meta_indices/scope_index.hpp" #include "meta_indices/scope_index.hpp"
#include "meta_indices/variable_index.hpp" #include "meta_indices/variable_index.hpp"
#include "meta_states.hpp" #include "meta_states.hpp"
#include "meta_states/ctor.hpp" #include "meta_states/argument.hpp"
#include "meta_states/dtor.hpp" #include "meta_states/constructor.hpp"
#include "meta_states/destructor.hpp"
#include "meta_states/evalue.hpp" #include "meta_states/evalue.hpp"
#include "meta_states/function.hpp" #include "meta_states/function.hpp"
#include "meta_states/member.hpp" #include "meta_states/member.hpp"
#include "meta_states/method.hpp" #include "meta_states/method.hpp"
#include "meta_states/parameter.hpp"
#include "meta_states/scope.hpp" #include "meta_states/scope.hpp"
#include "meta_states/variable.hpp" #include "meta_states/variable.hpp"
@@ -39,8 +39,8 @@
#include "meta_types/any_type.hpp" #include "meta_types/any_type.hpp"
#include "meta_types/array_type.hpp" #include "meta_types/array_type.hpp"
#include "meta_types/class_type.hpp" #include "meta_types/class_type.hpp"
#include "meta_types/ctor_type.hpp" #include "meta_types/constructor_type.hpp"
#include "meta_types/dtor_type.hpp" #include "meta_types/destructor_type.hpp"
#include "meta_types/enum_type.hpp" #include "meta_types/enum_type.hpp"
#include "meta_types/function_type.hpp" #include "meta_types/function_type.hpp"
#include "meta_types/member_type.hpp" #include "meta_types/member_type.hpp"

View File

@@ -103,35 +103,35 @@ namespace meta_hpp
namespace meta_hpp namespace meta_hpp
{ {
class ctor; class argument;
class dtor; class constructor;
class destructor;
class evalue; class evalue;
class function; class function;
class member; class member;
class method; class method;
class parameter;
class scope; class scope;
class variable; class variable;
namespace detail namespace detail
{ {
struct ctor_state; struct argument_state;
struct dtor_state; struct constructor_state;
struct destructor_state;
struct evalue_state; struct evalue_state;
struct function_state; struct function_state;
struct member_state; struct member_state;
struct method_state; struct method_state;
struct parameter_state;
struct scope_state; struct scope_state;
struct variable_state; struct variable_state;
using ctor_state_ptr = std::shared_ptr<ctor_state>; using argument_state_ptr = std::shared_ptr<argument_state>;
using dtor_state_ptr = std::shared_ptr<dtor_state>; using constructor_state_ptr = std::shared_ptr<constructor_state>;
using destructor_state_ptr = std::shared_ptr<destructor_state>;
using evalue_state_ptr = std::shared_ptr<evalue_state>; using evalue_state_ptr = std::shared_ptr<evalue_state>;
using function_state_ptr = std::shared_ptr<function_state>; using function_state_ptr = std::shared_ptr<function_state>;
using member_state_ptr = std::shared_ptr<member_state>; using member_state_ptr = std::shared_ptr<member_state>;
using method_state_ptr = std::shared_ptr<method_state>; using method_state_ptr = std::shared_ptr<method_state>;
using parameter_state_ptr = std::shared_ptr<parameter_state>;
using scope_state_ptr = std::shared_ptr<scope_state>; using scope_state_ptr = std::shared_ptr<scope_state>;
using variable_state_ptr = std::shared_ptr<variable_state>; using variable_state_ptr = std::shared_ptr<variable_state>;
} }
@@ -142,8 +142,8 @@ namespace meta_hpp
class any_type; class any_type;
class array_type; class array_type;
class class_type; class class_type;
class ctor_type; class constructor_type;
class dtor_type; class destructor_type;
class enum_type; class enum_type;
class function_type; class function_type;
class member_type; class member_type;
@@ -159,8 +159,8 @@ namespace meta_hpp
struct type_data_base; struct type_data_base;
struct array_type_data; struct array_type_data;
struct class_type_data; struct class_type_data;
struct ctor_type_data; struct constructor_type_data;
struct dtor_type_data; struct destructor_type_data;
struct enum_type_data; struct enum_type_data;
struct function_type_data; struct function_type_data;
struct member_type_data; struct member_type_data;
@@ -174,8 +174,8 @@ namespace meta_hpp
using type_data_base_ptr = std::shared_ptr<type_data_base>; using type_data_base_ptr = std::shared_ptr<type_data_base>;
using array_type_data_ptr = std::shared_ptr<array_type_data>; using array_type_data_ptr = std::shared_ptr<array_type_data>;
using class_type_data_ptr = std::shared_ptr<class_type_data>; using class_type_data_ptr = std::shared_ptr<class_type_data>;
using ctor_type_data_ptr = std::shared_ptr<ctor_type_data>; using constructor_type_data_ptr = std::shared_ptr<constructor_type_data>;
using dtor_type_data_ptr = std::shared_ptr<dtor_type_data>; using destructor_type_data_ptr = std::shared_ptr<destructor_type_data>;
using enum_type_data_ptr = std::shared_ptr<enum_type_data>; using enum_type_data_ptr = std::shared_ptr<enum_type_data>;
using function_type_data_ptr = std::shared_ptr<function_type_data>; using function_type_data_ptr = std::shared_ptr<function_type_data>;
using member_type_data_ptr = std::shared_ptr<member_type_data>; using member_type_data_ptr = std::shared_ptr<member_type_data>;
@@ -190,33 +190,33 @@ namespace meta_hpp
namespace meta_hpp namespace meta_hpp
{ {
class ctor_index; class argument_index;
class dtor_index; class constructor_index;
class destructor_index;
class evalue_index; class evalue_index;
class function_index; class function_index;
class member_index; class member_index;
class method_index; class method_index;
class parameter_index;
class scope_index; class scope_index;
class variable_index; class variable_index;
} }
namespace meta_hpp namespace meta_hpp
{ {
using argument_list = std::vector<argument>;
using class_set = std::set<class_type, std::less<>>; using class_set = std::set<class_type, std::less<>>;
using class_map = std::map<std::string, class_type, std::less<>>; using class_map = std::map<std::string, class_type, std::less<>>;
using enum_set = std::set<enum_type, std::less<>>; using enum_set = std::set<enum_type, std::less<>>;
using enum_map = std::map<std::string, enum_type, std::less<>>; using enum_map = std::map<std::string, enum_type, std::less<>>;
using ctor_map = std::map<ctor_index, ctor, std::less<>>; using constructor_map = std::map<constructor_index, constructor, std::less<>>;
using dtor_map = std::map<dtor_index, dtor, std::less<>>; using destructor_map = std::map<destructor_index, destructor, std::less<>>;
using evalue_map = std::map<evalue_index, evalue, std::less<>>; using evalue_map = std::map<evalue_index, evalue, std::less<>>;
using function_map = std::map<function_index, function, std::less<>>; using function_map = std::map<function_index, function, std::less<>>;
using member_map = std::map<member_index, member, std::less<>>; using member_map = std::map<member_index, member, std::less<>>;
using method_map = std::map<method_index, method, std::less<>>; using method_map = std::map<method_index, method, std::less<>>;
using scope_map = std::map<scope_index, scope, std::less<>>; using scope_map = std::map<scope_index, scope, std::less<>>;
using variable_map = std::map<variable_index, variable, std::less<>>; using variable_map = std::map<variable_index, variable, std::less<>>;
using parameter_list = std::vector<parameter>;
} }

View File

@@ -50,8 +50,8 @@ namespace meta_hpp::detail
enum class type_kind : std::uint32_t { enum class type_kind : std::uint32_t {
array_, array_,
class_, class_,
ctor_, constructor_,
dtor_, destructor_,
enum_, enum_,
function_, function_,
member_, member_,

View File

@@ -14,12 +14,12 @@ namespace meta_hpp
namespace detail namespace detail
{ {
template < typename Class, typename... Args > template < typename Class, typename... Args >
concept class_bind_ctor_kind = concept class_bind_constructor_kind =
class_kind<Class> && class_kind<Class> &&
requires(Args&&... args) { { Class{std::forward<Args>(args)...} }; }; requires(Args&&... args) { { Class{std::forward<Args>(args)...} }; };
template < typename Class > template < typename Class >
concept class_bind_dtor_kind = concept class_bind_destructor_kind =
class_kind<Class> && class_kind<Class> &&
requires(Class&& inst) { { inst.~Class() }; }; requires(Class&& inst) { { inst.~Class() }; };
@@ -46,19 +46,19 @@ namespace meta_hpp
operator class_type() const noexcept; operator class_type() const noexcept;
template < typename... Args template < typename... Args
, ctor_policy_kind Policy = ctor_policy::as_object > , constructor_policy_kind Policy = constructor_policy::as_object >
class_bind& ctor_(Policy = Policy{}) class_bind& constructor_(Policy = Policy{})
requires detail::class_bind_ctor_kind<Class, Args...>; requires detail::class_bind_constructor_kind<Class, Args...>;
template < typename... Args template < typename... Args
, ctor_policy_kind Policy = ctor_policy::as_object > , constructor_policy_kind Policy = constructor_policy::as_object >
class_bind& ctor_( class_bind& constructor_(
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
Policy = Policy{}) Policy = Policy{})
requires detail::class_bind_ctor_kind<Class, Args...>; requires detail::class_bind_constructor_kind<Class, Args...>;
class_bind& dtor_() class_bind& destructor_()
requires detail::class_bind_dtor_kind<Class>; requires detail::class_bind_destructor_kind<Class>;
template < detail::class_kind Base > template < detail::class_kind Base >
class_bind& base_() class_bind& base_()
@@ -73,7 +73,7 @@ namespace meta_hpp
class_bind& function_( class_bind& function_(
std::string name, std::string name,
Function function, Function function,
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
Policy = Policy{}); Policy = Policy{});
template < detail::member_kind Member template < detail::member_kind Member
@@ -91,7 +91,7 @@ namespace meta_hpp
class_bind& method_( class_bind& method_(
std::string name, std::string name,
Method method, Method method,
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
Policy = Policy{}) Policy = Policy{})
requires detail::class_bind_method_kind<Class, Method>; requires detail::class_bind_method_kind<Class, Method>;
@@ -143,7 +143,7 @@ namespace meta_hpp
scope_bind& function_( scope_bind& function_(
std::string name, std::string name,
Function function, Function function,
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
Policy = Policy{}); Policy = Policy{});
template < detail::pointer_kind Pointer template < detail::pointer_kind Pointer

View File

@@ -23,41 +23,41 @@ namespace meta_hpp
} }
template < detail::class_kind Class > template < detail::class_kind Class >
template < typename... Args, ctor_policy_kind Policy > template < typename... Args, constructor_policy_kind Policy >
class_bind<Class>& class_bind<Class>::ctor_(Policy policy) class_bind<Class>& class_bind<Class>::constructor_(Policy policy)
requires detail::class_bind_ctor_kind<Class, Args...> requires detail::class_bind_constructor_kind<Class, Args...>
{ {
return ctor_<Args...>({}, policy); return constructor_<Args...>({}, policy);
} }
template < detail::class_kind Class > template < detail::class_kind Class >
template < typename... Args, ctor_policy_kind Policy > template < typename... Args, constructor_policy_kind Policy >
class_bind<Class>& class_bind<Class>::ctor_( class_bind<Class>& class_bind<Class>::constructor_(
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
[[maybe_unused]] Policy policy) [[maybe_unused]] Policy policy)
requires detail::class_bind_ctor_kind<Class, Args...> requires detail::class_bind_constructor_kind<Class, Args...>
{ {
auto ctor_state = detail::ctor_state::make<Policy, Class, Args...>(); auto constructor_state = detail::constructor_state::make<Policy, Class, Args...>();
if ( pnames.size() > ctor_state->parameters.size() ) { if ( anames.size() > constructor_state->arguments.size() ) {
detail::throw_exception_with("provided parameter names don't match constructor argument count"); detail::throw_exception_with("provided argument names don't match constructor argument count");
} }
for ( std::size_t i = 0; i < pnames.size(); ++i ) { for ( std::size_t i = 0; i < anames.size(); ++i ) {
parameter& param = ctor_state->parameters[i]; argument& arg = constructor_state->arguments[i];
detail::state_access(param)->name = std::string{std::data(pnames)[i]}; detail::state_access(arg)->name = std::string{std::data(anames)[i]};
} }
data_->ctors.emplace(ctor_state->index, std::move(ctor_state)); data_->constructors.emplace(constructor_state->index, std::move(constructor_state));
return *this; return *this;
} }
template < detail::class_kind Class > template < detail::class_kind Class >
class_bind<Class>& class_bind<Class>::dtor_() class_bind<Class>& class_bind<Class>::destructor_()
requires detail::class_bind_dtor_kind<Class> requires detail::class_bind_destructor_kind<Class>
{ {
auto dtor_state = detail::dtor_state::make<Class>(); auto destructor_state = detail::destructor_state::make<Class>();
data_->dtors.emplace(dtor_state->index, std::move(dtor_state)); data_->destructors.emplace(destructor_state->index, std::move(destructor_state));
return *this; return *this;
} }
@@ -86,18 +86,18 @@ namespace meta_hpp
class_bind<Class>& class_bind<Class>::function_( class_bind<Class>& class_bind<Class>::function_(
std::string name, std::string name,
Function function, Function function,
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
[[maybe_unused]] Policy policy) [[maybe_unused]] Policy policy)
{ {
auto function_state = detail::function_state::make<Policy>(std::move(name), std::move(function)); auto function_state = detail::function_state::make<Policy>(std::move(name), std::move(function));
if ( pnames.size() > function_state->parameters.size() ) { if ( anames.size() > function_state->arguments.size() ) {
detail::throw_exception_with("provided parameter names don't match function argument count"); detail::throw_exception_with("provided argument names don't match function argument count");
} }
for ( std::size_t i = 0; i < pnames.size(); ++i ) { for ( std::size_t i = 0; i < anames.size(); ++i ) {
parameter& param = function_state->parameters[i]; argument& arg = function_state->arguments[i];
detail::state_access(param)->name = std::string{std::data(pnames)[i]}; detail::state_access(arg)->name = std::string{std::data(anames)[i]};
} }
data_->functions.emplace(function_state->index, std::move(function_state)); data_->functions.emplace(function_state->index, std::move(function_state));
@@ -127,19 +127,19 @@ namespace meta_hpp
class_bind<Class>& class_bind<Class>::method_( class_bind<Class>& class_bind<Class>::method_(
std::string name, std::string name,
Method method, Method method,
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
[[maybe_unused]] Policy policy) [[maybe_unused]] Policy policy)
requires detail::class_bind_method_kind<Class, Method> requires detail::class_bind_method_kind<Class, Method>
{ {
auto method_state = detail::method_state::make<Policy>(std::move(name), std::move(method)); auto method_state = detail::method_state::make<Policy>(std::move(name), std::move(method));
if ( pnames.size() > method_state->parameters.size() ) { if ( anames.size() > method_state->arguments.size() ) {
detail::throw_exception_with("provided parameter names don't match method argument count"); detail::throw_exception_with("provided argument names don't match method argument count");
} }
for ( std::size_t i = 0; i < pnames.size(); ++i ) { for ( std::size_t i = 0; i < anames.size(); ++i ) {
parameter& param = method_state->parameters[i]; argument& arg = method_state->arguments[i];
detail::state_access(param)->name = std::string{std::data(pnames)[i]}; detail::state_access(arg)->name = std::string{std::data(anames)[i]};
} }
data_->methods.emplace(method_state->index, std::move(method_state)); data_->methods.emplace(method_state->index, std::move(method_state));

View File

@@ -47,18 +47,18 @@ namespace meta_hpp
scope_bind& scope_bind::function_( scope_bind& scope_bind::function_(
std::string name, std::string name,
Function function, Function function,
std::initializer_list<std::string_view> pnames, std::initializer_list<std::string_view> anames,
[[maybe_unused]] Policy policy) [[maybe_unused]] Policy policy)
{ {
auto function_state = detail::function_state::make<Policy>(std::move(name), std::move(function)); auto function_state = detail::function_state::make<Policy>(std::move(name), std::move(function));
if ( pnames.size() > function_state->parameters.size() ) { if ( anames.size() > function_state->arguments.size() ) {
detail::throw_exception_with("provided parameter names don't match function argument count"); detail::throw_exception_with("provided argument names don't match function argument count");
} }
for ( std::size_t i = 0; i < pnames.size(); ++i ) { for ( std::size_t i = 0; i < anames.size(); ++i ) {
parameter& param = function_state->parameters[i]; argument& arg = function_state->arguments[i];
detail::state_access(param)->name = std::string{std::data(pnames)[i]}; detail::state_access(arg)->name = std::string{std::data(anames)[i]};
} }
state_->functions.emplace(function_state->index, std::move(function_state)); state_->functions.emplace(function_state->index, std::move(function_state));

View File

@@ -12,13 +12,13 @@ namespace meta_hpp::detail
{ {
template < typename T > template < typename T >
inline constexpr bool is_state_family_v = inline constexpr bool is_state_family_v =
std::is_same_v<T, ctor> || std::is_same_v<T, argument> ||
std::is_same_v<T, dtor> || std::is_same_v<T, constructor> ||
std::is_same_v<T, destructor> ||
std::is_same_v<T, evalue> || std::is_same_v<T, evalue> ||
std::is_same_v<T, function> || std::is_same_v<T, function> ||
std::is_same_v<T, member> || std::is_same_v<T, member> ||
std::is_same_v<T, method> || std::is_same_v<T, method> ||
std::is_same_v<T, parameter> ||
std::is_same_v<T, scope> || std::is_same_v<T, scope> ||
std::is_same_v<T, variable>; std::is_same_v<T, variable>;

View File

@@ -15,8 +15,8 @@ namespace meta_hpp::detail
std::is_same_v<T, any_type> || std::is_same_v<T, any_type> ||
std::is_same_v<T, array_type> || std::is_same_v<T, array_type> ||
std::is_same_v<T, class_type> || std::is_same_v<T, class_type> ||
std::is_same_v<T, ctor_type> || std::is_same_v<T, constructor_type> ||
std::is_same_v<T, dtor_type> || std::is_same_v<T, destructor_type> ||
std::is_same_v<T, enum_type> || std::is_same_v<T, enum_type> ||
std::is_same_v<T, function_type> || std::is_same_v<T, function_type> ||
std::is_same_v<T, member_type> || std::is_same_v<T, member_type> ||

View File

@@ -82,10 +82,10 @@ namespace meta_hpp::detail
[[nodiscard]] class_type resolve_class_type() { return class_type{resolve_class_type_data<Class>()}; } [[nodiscard]] class_type resolve_class_type() { return class_type{resolve_class_type_data<Class>()}; }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
[[nodiscard]] ctor_type resolve_ctor_type() { return ctor_type{resolve_ctor_type_data<Class, Args...>()}; } [[nodiscard]] constructor_type resolve_constructor_type() { return constructor_type{resolve_constructor_type_data<Class, Args...>()}; }
template < class_kind Class > template < class_kind Class >
[[nodiscard]] dtor_type resolve_dtor_type() { return dtor_type{resolve_dtor_type_data<Class>()}; } [[nodiscard]] destructor_type resolve_destructor_type() { return destructor_type{resolve_destructor_type_data<Class>()}; }
template < enum_kind Enum > template < enum_kind Enum >
[[nodiscard]] enum_type resolve_enum_type() { return enum_type{resolve_enum_type_data<Enum>()}; } [[nodiscard]] enum_type resolve_enum_type() { return enum_type{resolve_enum_type_data<Enum>()}; }
@@ -131,14 +131,14 @@ namespace meta_hpp::detail
} }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
[[nodiscard]] ctor_type_data_ptr resolve_ctor_type_data() { [[nodiscard]] constructor_type_data_ptr resolve_constructor_type_data() {
static ctor_type_data_ptr data{std::make_shared<ctor_type_data>(type_list<Class>{}, type_list<Args...>{})}; static constructor_type_data_ptr data{std::make_shared<constructor_type_data>(type_list<Class>{}, type_list<Args...>{})};
return data; return data;
} }
template < class_kind Class > template < class_kind Class >
[[nodiscard]] dtor_type_data_ptr resolve_dtor_type_data() { [[nodiscard]] destructor_type_data_ptr resolve_destructor_type_data() {
static dtor_type_data_ptr data{std::make_shared<dtor_type_data>(type_list<Class>{})}; static destructor_type_data_ptr data{std::make_shared<destructor_type_data>(type_list<Class>{})};
return data; return data;
} }
@@ -234,15 +234,15 @@ namespace meta_hpp::detail
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
ctor_type resolve_ctor_type() { constructor_type resolve_constructor_type() {
type_registry& registry = type_registry::instance(); type_registry& registry = type_registry::instance();
return registry.resolve_ctor_type<Class, Args...>(); return registry.resolve_constructor_type<Class, Args...>();
} }
template < class_kind Class > template < class_kind Class >
dtor_type resolve_dtor_type() { destructor_type resolve_destructor_type() {
type_registry& registry = type_registry::instance(); type_registry& registry = type_registry::instance();
return registry.resolve_dtor_type<Class>(); return registry.resolve_destructor_type<Class>();
} }
} }

View File

@@ -10,28 +10,28 @@
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
enum class ctor_flags : std::uint32_t { enum class constructor_flags : std::uint32_t {
is_noexcept = 1 << 0, is_noexcept = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(ctor_flags) ENUM_HPP_OPERATORS_DECL(constructor_flags)
using ctor_bitflags = bitflags<ctor_flags>; using constructor_bitflags = bitflags<constructor_flags>;
} }
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
struct ctor_traits { struct constructor_traits {
static constexpr std::size_t arity{sizeof...(Args)}; static constexpr std::size_t arity{sizeof...(Args)};
using class_type = Class; using class_type = Class;
using argument_types = type_list<Args...>; using argument_types = type_list<Args...>;
[[nodiscard]] static constexpr ctor_bitflags make_flags() noexcept { [[nodiscard]] static constexpr constructor_bitflags make_flags() noexcept {
ctor_bitflags flags{}; constructor_bitflags flags{};
if constexpr ( std::is_nothrow_constructible_v<Class, Args...> ) { if constexpr ( std::is_nothrow_constructible_v<Class, Args...> ) {
flags.set(ctor_flags::is_noexcept); flags.set(constructor_flags::is_noexcept);
} }
return flags; return flags;

View File

@@ -10,25 +10,25 @@
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
enum class dtor_flags : std::uint32_t { enum class destructor_flags : std::uint32_t {
is_noexcept = 1 << 0, is_noexcept = 1 << 0,
}; };
ENUM_HPP_OPERATORS_DECL(dtor_flags) ENUM_HPP_OPERATORS_DECL(destructor_flags)
using dtor_bitflags = bitflags<dtor_flags>; using destructor_bitflags = bitflags<destructor_flags>;
} }
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class > template < class_kind Class >
struct dtor_traits { struct destructor_traits {
using class_type = Class; using class_type = Class;
[[nodiscard]] static constexpr dtor_bitflags make_flags() noexcept { [[nodiscard]] static constexpr destructor_bitflags make_flags() noexcept {
dtor_bitflags flags{}; destructor_bitflags flags{};
if constexpr ( std::is_nothrow_destructible_v<Class> ) { if constexpr ( std::is_nothrow_destructible_v<Class> ) {
flags.set(dtor_flags::is_noexcept); flags.set(destructor_flags::is_noexcept);
} }
return flags; return flags;

View File

@@ -11,36 +11,54 @@
namespace meta_hpp namespace meta_hpp
{ {
class ctor_index final { class argument_index final {
public: public:
ctor_index() = delete; argument_index() = delete;
[[nodiscard]] const ctor_type& get_type() const noexcept; [[nodiscard]] const any_type& get_type() const noexcept;
[[nodiscard]] std::size_t get_position() const noexcept;
private: private:
friend detail::ctor_state; friend detail::argument_state;
template < detail::class_kind Class, typename... Args > template < typename Argument >
[[nodiscard]] static ctor_index make(); [[nodiscard]] static argument_index make(std::size_t position);
private: private:
explicit ctor_index(ctor_type type); explicit argument_index(any_type type, std::size_t position);
friend bool operator<(const ctor_index& l, const ctor_index& r) noexcept; friend bool operator<(const argument_index& l, const argument_index& r) noexcept;
friend bool operator==(const ctor_index& l, const ctor_index& r) noexcept; friend bool operator==(const argument_index& l, const argument_index& r) noexcept;
private: private:
ctor_type type_; any_type type_;
std::size_t position_{};
}; };
class dtor_index final { class constructor_index final {
public: public:
dtor_index() = delete; constructor_index() = delete;
[[nodiscard]] const dtor_type& get_type() const noexcept; [[nodiscard]] const constructor_type& get_type() const noexcept;
private: private:
friend detail::dtor_state; friend detail::constructor_state;
template < detail::class_kind Class, typename... Args >
[[nodiscard]] static constructor_index make();
private:
explicit constructor_index(constructor_type type);
friend bool operator<(const constructor_index& l, const constructor_index& r) noexcept;
friend bool operator==(const constructor_index& l, const constructor_index& r) noexcept;
private:
constructor_type type_;
};
class destructor_index final {
public:
destructor_index() = delete;
[[nodiscard]] const destructor_type& get_type() const noexcept;
private:
friend detail::destructor_state;
template < detail::class_kind Class > template < detail::class_kind Class >
[[nodiscard]] static dtor_index make(); [[nodiscard]] static destructor_index make();
private: private:
explicit dtor_index(dtor_type type); explicit destructor_index(destructor_type type);
friend bool operator<(const dtor_index& l, const dtor_index& r) noexcept; friend bool operator<(const destructor_index& l, const destructor_index& r) noexcept;
friend bool operator==(const dtor_index& l, const dtor_index& r) noexcept; friend bool operator==(const destructor_index& l, const destructor_index& r) noexcept;
private: private:
dtor_type type_; destructor_type type_;
}; };
class evalue_index final { class evalue_index final {
@@ -115,24 +133,6 @@ namespace meta_hpp
std::string name_; std::string name_;
}; };
class parameter_index final {
public:
parameter_index() = delete;
[[nodiscard]] const any_type& get_type() const noexcept;
[[nodiscard]] std::size_t get_position() const noexcept;
private:
friend detail::parameter_state;
template < typename Parameter >
[[nodiscard]] static parameter_index make(std::size_t position);
private:
explicit parameter_index(any_type type, std::size_t position);
friend bool operator<(const parameter_index& l, const parameter_index& r) noexcept;
friend bool operator==(const parameter_index& l, const parameter_index& r) noexcept;
private:
any_type type_;
std::size_t position_{};
};
class scope_index final { class scope_index final {
public: public:
scope_index() = delete; scope_index() = delete;

View File

@@ -14,28 +14,28 @@
namespace meta_hpp namespace meta_hpp
{ {
inline parameter_index::parameter_index(any_type type, std::size_t position) inline argument_index::argument_index(any_type type, std::size_t position)
: type_{std::move(type)} : type_{std::move(type)}
, position_{position} {} , position_{position} {}
template < typename Parameter > template < typename Argument >
inline parameter_index parameter_index::make(std::size_t position) { inline argument_index argument_index::make(std::size_t position) {
return parameter_index{detail::resolve_type<Parameter>(), position}; return argument_index{detail::resolve_type<Argument>(), position};
} }
inline const any_type& parameter_index::get_type() const noexcept { inline const any_type& argument_index::get_type() const noexcept {
return type_; return type_;
} }
inline std::size_t parameter_index::get_position() const noexcept { inline std::size_t argument_index::get_position() const noexcept {
return position_; return position_;
} }
inline bool operator<(const parameter_index& l, const parameter_index& r) noexcept { inline bool operator<(const argument_index& l, const argument_index& r) noexcept {
return l.type_ < r.type_ || (l.type_ == r.type_ && l.position_ < r.position_); return l.type_ < r.type_ || (l.type_ == r.type_ && l.position_ < r.position_);
} }
inline bool operator==(const parameter_index& l, const parameter_index& r) noexcept { inline bool operator==(const argument_index& l, const argument_index& r) noexcept {
return l.type_ == r.type_ && l.position_ == r.position_; return l.type_ == r.type_ && l.position_ == r.position_;
} }
} }

View File

@@ -14,23 +14,23 @@
namespace meta_hpp namespace meta_hpp
{ {
inline ctor_index::ctor_index(ctor_type type) inline constructor_index::constructor_index(constructor_type type)
: type_{std::move(type)} {} : type_{std::move(type)} {}
template < detail::class_kind Class, typename... Args > template < detail::class_kind Class, typename... Args >
ctor_index ctor_index::make() { constructor_index constructor_index::make() {
return ctor_index{detail::resolve_ctor_type<Class, Args...>()}; return constructor_index{detail::resolve_constructor_type<Class, Args...>()};
} }
inline const ctor_type& ctor_index::get_type() const noexcept { inline const constructor_type& constructor_index::get_type() const noexcept {
return type_; return type_;
} }
inline bool operator<(const ctor_index& l, const ctor_index& r) noexcept { inline bool operator<(const constructor_index& l, const constructor_index& r) noexcept {
return l.type_ < r.type_; return l.type_ < r.type_;
} }
inline bool operator==(const ctor_index& l, const ctor_index& r) noexcept { inline bool operator==(const constructor_index& l, const constructor_index& r) noexcept {
return l.type_ == r.type_; return l.type_ == r.type_;
} }
} }

View File

@@ -14,23 +14,23 @@
namespace meta_hpp namespace meta_hpp
{ {
inline dtor_index::dtor_index(dtor_type type) inline destructor_index::destructor_index(destructor_type type)
: type_{std::move(type)} {} : type_{std::move(type)} {}
template < detail::class_kind Class > template < detail::class_kind Class >
dtor_index dtor_index::make() { destructor_index destructor_index::make() {
return dtor_index{detail::resolve_dtor_type<Class>()}; return destructor_index{detail::resolve_destructor_type<Class>()};
} }
inline const dtor_type& dtor_index::get_type() const noexcept { inline const destructor_type& destructor_index::get_type() const noexcept {
return type_; return type_;
} }
inline bool operator<(const dtor_index& l, const dtor_index& r) noexcept { inline bool operator<(const destructor_index& l, const destructor_index& r) noexcept {
return l.type_ < r.type_; return l.type_ < r.type_;
} }
inline bool operator==(const dtor_index& l, const dtor_index& r) noexcept { inline bool operator==(const destructor_index& l, const destructor_index& r) noexcept {
return l.type_ == r.type_; return l.type_ == r.type_;
} }
} }

View File

@@ -15,7 +15,7 @@
namespace meta_hpp namespace meta_hpp
{ {
namespace ctor_policy namespace constructor_policy
{ {
struct as_object final {}; struct as_object final {};
struct as_raw_pointer final {}; struct as_raw_pointer final {};
@@ -51,10 +51,10 @@ namespace meta_hpp
} }
template < typename Policy > template < typename Policy >
inline constexpr bool is_ctor_policy_v = inline constexpr bool is_constructor_policy_v =
std::is_same_v<Policy, ctor_policy::as_object> || std::is_same_v<Policy, constructor_policy::as_object> ||
std::is_same_v<Policy, ctor_policy::as_raw_pointer> || std::is_same_v<Policy, constructor_policy::as_raw_pointer> ||
std::is_same_v<Policy, ctor_policy::as_shared_pointer>; std::is_same_v<Policy, constructor_policy::as_shared_pointer>;
template < typename Policy > template < typename Policy >
inline constexpr bool is_function_policy_v = inline constexpr bool is_function_policy_v =
@@ -81,7 +81,7 @@ namespace meta_hpp
std::is_same_v<Policy, variable_policy::as_reference_wrapper>; std::is_same_v<Policy, variable_policy::as_reference_wrapper>;
template < typename Policy > template < typename Policy >
concept ctor_policy_kind = is_ctor_policy_v<Policy>; concept constructor_policy_kind = is_constructor_policy_v<Policy>;
template < typename Policy > template < typename Policy >
concept function_policy_kind = is_function_policy_v<Policy>; concept function_policy_kind = is_function_policy_v<Policy>;
@@ -98,16 +98,33 @@ namespace meta_hpp
namespace meta_hpp namespace meta_hpp
{ {
class ctor final { class argument final {
public: public:
explicit ctor() = default; explicit argument() = default;
explicit ctor(detail::ctor_state_ptr state); explicit argument(detail::argument_state_ptr state);
[[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const ctor_index& get_index() const noexcept; [[nodiscard]] const argument_index& get_index() const noexcept;
[[nodiscard]] const ctor_type& get_type() const noexcept; [[nodiscard]] const any_type& get_type() const noexcept;
[[nodiscard]] std::size_t get_position() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
private:
detail::argument_state_ptr state_;
friend auto detail::state_access<argument>(const argument&);
};
class constructor final {
public:
explicit constructor() = default;
explicit constructor(detail::constructor_state_ptr state);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const constructor_index& get_index() const noexcept;
[[nodiscard]] const constructor_type& get_type() const noexcept;
template < typename... Args > template < typename... Args >
uvalue invoke(Args&&... args) const; uvalue invoke(Args&&... args) const;
@@ -121,23 +138,23 @@ namespace meta_hpp
template < typename... Args > template < typename... Args >
[[nodiscard]] bool is_invocable_with(Args&&... args) const noexcept; [[nodiscard]] bool is_invocable_with(Args&&... args) const noexcept;
[[nodiscard]] parameter get_parameter(std::size_t position) const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept;
[[nodiscard]] const parameter_list& get_parameters() const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept;
private: private:
detail::ctor_state_ptr state_; detail::constructor_state_ptr state_;
friend auto detail::state_access<ctor>(const ctor&); friend auto detail::state_access<constructor>(const constructor&);
}; };
class dtor final { class destructor final {
public: public:
explicit dtor() = default; explicit destructor() = default;
explicit dtor(detail::dtor_state_ptr state); explicit destructor(detail::destructor_state_ptr state);
[[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const dtor_index& get_index() const noexcept; [[nodiscard]] const destructor_index& get_index() const noexcept;
[[nodiscard]] const dtor_type& get_type() const noexcept; [[nodiscard]] const destructor_type& get_type() const noexcept;
template < typename Arg > template < typename Arg >
void invoke(Arg&& ptr) const; void invoke(Arg&& ptr) const;
@@ -151,8 +168,8 @@ namespace meta_hpp
template < typename Arg > template < typename Arg >
[[nodiscard]] bool is_invocable_with(Arg&& ptr) const noexcept; [[nodiscard]] bool is_invocable_with(Arg&& ptr) const noexcept;
private: private:
detail::dtor_state_ptr state_; detail::destructor_state_ptr state_;
friend auto detail::state_access<dtor>(const dtor&); friend auto detail::state_access<destructor>(const destructor&);
}; };
class evalue final { class evalue final {
@@ -198,8 +215,8 @@ namespace meta_hpp
template < typename... Args > template < typename... Args >
[[nodiscard]] bool is_invocable_with(Args&&... args) const noexcept; [[nodiscard]] bool is_invocable_with(Args&&... args) const noexcept;
[[nodiscard]] parameter get_parameter(std::size_t position) const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept;
[[nodiscard]] const parameter_list& get_parameters() const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept;
private: private:
detail::function_state_ptr state_; detail::function_state_ptr state_;
friend auto detail::state_access<function>(const function&); friend auto detail::state_access<function>(const function&);
@@ -269,30 +286,13 @@ namespace meta_hpp
template < typename Instance, typename... Args > template < typename Instance, typename... Args >
[[nodiscard]] bool is_invocable_with(Instance&& instance, Args&&... args) const noexcept; [[nodiscard]] bool is_invocable_with(Instance&& instance, Args&&... args) const noexcept;
[[nodiscard]] parameter get_parameter(std::size_t position) const noexcept; [[nodiscard]] argument get_argument(std::size_t position) const noexcept;
[[nodiscard]] const parameter_list& get_parameters() const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept;
private: private:
detail::method_state_ptr state_; detail::method_state_ptr state_;
friend auto detail::state_access<method>(const method&); friend auto detail::state_access<method>(const method&);
}; };
class parameter final {
public:
explicit parameter() = default;
explicit parameter(detail::parameter_state_ptr state);
[[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] const parameter_index& get_index() const noexcept;
[[nodiscard]] const any_type& get_type() const noexcept;
[[nodiscard]] std::size_t get_position() const noexcept;
[[nodiscard]] const std::string& get_name() const noexcept;
private:
detail::parameter_state_ptr state_;
friend auto detail::state_access<parameter>(const parameter&);
};
class scope final { class scope final {
public: public:
explicit scope() = default; explicit scope() = default;
@@ -394,30 +394,30 @@ namespace meta_hpp
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
struct ctor_state final { struct constructor_state final {
using invoke_impl = fixed_function<uvalue(std::span<const uarg>)>; using invoke_impl = fixed_function<uvalue(std::span<const uarg>)>;
using is_invocable_with_impl = fixed_function<bool(std::span<const uarg_base>)>; using is_invocable_with_impl = fixed_function<bool(std::span<const uarg_base>)>;
ctor_index index; constructor_index index;
invoke_impl invoke; invoke_impl invoke;
is_invocable_with_impl is_invocable_with; is_invocable_with_impl is_invocable_with;
parameter_list parameters; argument_list arguments;
template < ctor_policy_kind Policy, class_kind Class, typename... Args > template < constructor_policy_kind Policy, class_kind Class, typename... Args >
[[nodiscard]] static ctor_state_ptr make(); [[nodiscard]] static constructor_state_ptr make();
}; };
struct dtor_state final { struct destructor_state final {
using invoke_impl = fixed_function<void(const uarg&)>; using invoke_impl = fixed_function<void(const uarg&)>;
using is_invocable_with_impl = fixed_function<bool(const uarg_base&)>; using is_invocable_with_impl = fixed_function<bool(const uarg_base&)>;
dtor_index index; destructor_index index;
invoke_impl invoke; invoke_impl invoke;
is_invocable_with_impl is_invocable_with; is_invocable_with_impl is_invocable_with;
template < class_kind Class > template < class_kind Class >
[[nodiscard]] static dtor_state_ptr make(); [[nodiscard]] static destructor_state_ptr make();
}; };
struct evalue_state final { struct evalue_state final {
@@ -437,7 +437,7 @@ namespace meta_hpp::detail
invoke_impl invoke; invoke_impl invoke;
is_invocable_with_impl is_invocable_with; is_invocable_with_impl is_invocable_with;
parameter_list parameters; argument_list arguments;
template < function_policy_kind Policy, function_kind Function > template < function_policy_kind Policy, function_kind Function >
[[nodiscard]] static function_state_ptr make(std::string name, Function function); [[nodiscard]] static function_state_ptr make(std::string name, Function function);
@@ -468,19 +468,19 @@ namespace meta_hpp::detail
invoke_impl invoke; invoke_impl invoke;
is_invocable_with_impl is_invocable_with; is_invocable_with_impl is_invocable_with;
parameter_list parameters; argument_list arguments;
template < method_policy_kind Policy, method_kind Method > template < method_policy_kind Policy, method_kind Method >
[[nodiscard]] static method_state_ptr make(std::string name, Method method); [[nodiscard]] static method_state_ptr make(std::string name, Method method);
}; };
struct parameter_state final { struct argument_state final {
parameter_index index; argument_index index;
std::string name{}; std::string name{};
template < typename Parameter > template < typename Argument >
[[nodiscard]] static parameter_state_ptr make(std::size_t position); [[nodiscard]] static argument_state_ptr make(std::size_t position);
}; };
struct scope_state final { struct scope_state final {

View File

@@ -11,10 +11,10 @@
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < typename Parameter > template < typename Argument >
inline parameter_state_ptr parameter_state::make(std::size_t position) { inline argument_state_ptr argument_state::make(std::size_t position) {
return std::make_shared<parameter_state>(parameter_state{ return std::make_shared<argument_state>(argument_state{
.index{parameter_index::make<Parameter>(position)}, .index{argument_index::make<Argument>(position)},
}); });
} }
} }
@@ -22,30 +22,30 @@ namespace meta_hpp::detail
namespace meta_hpp namespace meta_hpp
{ {
inline parameter::parameter(detail::parameter_state_ptr state) inline argument::argument(detail::argument_state_ptr state)
: state_{std::move(state)} {} : state_{std::move(state)} {}
inline bool parameter::is_valid() const noexcept { inline bool argument::is_valid() const noexcept {
return !!state_; return !!state_;
} }
inline parameter::operator bool() const noexcept { inline argument::operator bool() const noexcept {
return is_valid(); return is_valid();
} }
inline const parameter_index& parameter::get_index() const noexcept { inline const argument_index& argument::get_index() const noexcept {
return state_->index; return state_->index;
} }
inline const any_type& parameter::get_type() const noexcept { inline const any_type& argument::get_type() const noexcept {
return state_->index.get_type(); return state_->index.get_type();
} }
inline std::size_t parameter::get_position() const noexcept { inline std::size_t argument::get_position() const noexcept {
return state_->index.get_position(); return state_->index.get_position();
} }
inline const std::string& parameter::get_name() const noexcept { inline const std::string& argument::get_name() const noexcept {
return state_->name; return state_->name;
} }
} }

View File

@@ -9,26 +9,26 @@
#include "../meta_base.hpp" #include "../meta_base.hpp"
#include "../meta_states.hpp" #include "../meta_states.hpp"
#include "../meta_types/ctor_type.hpp" #include "../meta_types/constructor_type.hpp"
#include "../meta_detail/value_utilities/uarg.hpp" #include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < ctor_policy_kind Policy, class_kind Class, typename... Args > template < constructor_policy_kind Policy, class_kind Class, typename... Args >
uvalue raw_ctor_invoke(std::span<const uarg> args) { uvalue raw_constructor_invoke(std::span<const uarg> args) {
using ct = ctor_traits<Class, Args...>; using ct = constructor_traits<Class, Args...>;
using class_type = typename ct::class_type; using class_type = typename ct::class_type;
using argument_types = typename ct::argument_types; using argument_types = typename ct::argument_types;
constexpr bool as_object = constexpr bool as_object =
stdex::copy_constructible<class_type> && stdex::copy_constructible<class_type> &&
stdex::same_as<Policy, ctor_policy::as_object>; stdex::same_as<Policy, constructor_policy::as_object>;
constexpr bool as_raw_ptr = constexpr bool as_raw_ptr =
stdex::same_as<Policy, ctor_policy::as_raw_pointer>; stdex::same_as<Policy, constructor_policy::as_raw_pointer>;
constexpr bool as_shared_ptr = constexpr bool as_shared_ptr =
stdex::same_as<Policy, ctor_policy::as_shared_pointer>; stdex::same_as<Policy, constructor_policy::as_shared_pointer>;
static_assert(as_object || as_raw_ptr || as_shared_ptr); static_assert(as_object || as_raw_ptr || as_shared_ptr);
@@ -62,8 +62,8 @@ namespace meta_hpp::detail
} }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
bool raw_ctor_is_invocable_with(std::span<const uarg_base> args) { bool raw_constructor_is_invocable_with(std::span<const uarg_base> args) {
using ct = ctor_traits<Class, Args...>; using ct = constructor_traits<Class, Args...>;
using argument_types = typename ct::argument_types; using argument_types = typename ct::argument_types;
if ( args.size() != ct::arity ) { if ( args.size() != ct::arity ) {
@@ -79,71 +79,71 @@ namespace meta_hpp::detail
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < ctor_policy_kind Policy, class_kind Class, typename... Args > template < constructor_policy_kind Policy, class_kind Class, typename... Args >
ctor_state::invoke_impl make_ctor_invoke() { constructor_state::invoke_impl make_constructor_invoke() {
return &raw_ctor_invoke<Policy, Class, Args...>; return &raw_constructor_invoke<Policy, Class, Args...>;
} }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
ctor_state::is_invocable_with_impl make_ctor_is_invocable_with() { constructor_state::is_invocable_with_impl make_constructor_is_invocable_with() {
return &raw_ctor_is_invocable_with<Class, Args...>; return &raw_constructor_is_invocable_with<Class, Args...>;
} }
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
parameter_list make_ctor_parameters() { argument_list make_constructor_arguments() {
using ct = detail::ctor_traits<Class, Args...>; using ct = detail::constructor_traits<Class, Args...>;
parameter_list parameters; argument_list arguments;
parameters.reserve(ct::arity); arguments.reserve(ct::arity);
// NOLINTNEXTLINE(readability-named-parameter) // NOLINTNEXTLINE(readability-named-parameter)
[&parameters]<std::size_t... Is>(std::index_sequence<Is...>) mutable { [&arguments]<std::size_t... Is>(std::index_sequence<Is...>) mutable {
(parameters.push_back([]<std::size_t I>(){ (arguments.push_back([]<std::size_t I>(){
using P = detail::type_list_at_t<I, typename ct::argument_types>; using P = detail::type_list_at_t<I, typename ct::argument_types>;
return parameter{detail::parameter_state::make<P>(I)}; return argument{detail::argument_state::make<P>(I)};
}.template operator()<Is>()), ...); }.template operator()<Is>()), ...);
}(std::make_index_sequence<ct::arity>()); }(std::make_index_sequence<ct::arity>());
return parameters; return arguments;
} }
} }
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < ctor_policy_kind Policy, class_kind Class, typename... Args > template < constructor_policy_kind Policy, class_kind Class, typename... Args >
ctor_state_ptr ctor_state::make() { constructor_state_ptr constructor_state::make() {
return std::make_shared<ctor_state>(ctor_state{ return std::make_shared<constructor_state>(constructor_state{
.index{ctor_index::make<Class, Args...>()}, .index{constructor_index::make<Class, Args...>()},
.invoke{make_ctor_invoke<Policy, Class, Args...>()}, .invoke{make_constructor_invoke<Policy, Class, Args...>()},
.is_invocable_with{make_ctor_is_invocable_with<Class, Args...>()}, .is_invocable_with{make_constructor_is_invocable_with<Class, Args...>()},
.parameters{make_ctor_parameters<Class, Args...>()}, .arguments{make_constructor_arguments<Class, Args...>()},
}); });
} }
} }
namespace meta_hpp namespace meta_hpp
{ {
inline ctor::ctor(detail::ctor_state_ptr state) inline constructor::constructor(detail::constructor_state_ptr state)
: state_{std::move(state)} {} : state_{std::move(state)} {}
inline bool ctor::is_valid() const noexcept { inline bool constructor::is_valid() const noexcept {
return !!state_; return !!state_;
} }
inline ctor::operator bool() const noexcept { inline constructor::operator bool() const noexcept {
return is_valid(); return is_valid();
} }
inline const ctor_index& ctor::get_index() const noexcept { inline const constructor_index& constructor::get_index() const noexcept {
return state_->index; return state_->index;
} }
inline const ctor_type& ctor::get_type() const noexcept { inline const constructor_type& constructor::get_type() const noexcept {
return state_->index.get_type(); return state_->index.get_type();
} }
template < typename... Args > template < typename... Args >
uvalue ctor::invoke(Args&&... args) const { uvalue constructor::invoke(Args&&... args) const {
if constexpr ( sizeof...(Args) > 0 ) { if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail; using namespace detail;
const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...}; const std::array<uarg, sizeof...(Args)> vargs{uarg{std::forward<Args>(args)}...};
@@ -154,12 +154,12 @@ namespace meta_hpp
} }
template < typename... Args > template < typename... Args >
uvalue ctor::operator()(Args&&... args) const { uvalue constructor::operator()(Args&&... args) const {
return invoke(std::forward<Args>(args)...); return invoke(std::forward<Args>(args)...);
} }
template < typename... Args > template < typename... Args >
bool ctor::is_invocable_with() const noexcept { bool constructor::is_invocable_with() const noexcept {
if constexpr ( sizeof...(Args) > 0 ) { if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail; using namespace detail;
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...}; const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{type_list<Args>{}}...};
@@ -170,7 +170,7 @@ namespace meta_hpp
} }
template < typename... Args > template < typename... Args >
bool ctor::is_invocable_with(Args&&... args) const noexcept { bool constructor::is_invocable_with(Args&&... args) const noexcept {
if constexpr ( sizeof...(Args) > 0 ) { if constexpr ( sizeof...(Args) > 0 ) {
using namespace detail; using namespace detail;
const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...}; const std::array<uarg_base, sizeof...(Args)> vargs{uarg_base{std::forward<Args>(args)}...};
@@ -180,11 +180,11 @@ namespace meta_hpp
} }
} }
inline parameter ctor::get_parameter(std::size_t position) const noexcept { inline argument constructor::get_argument(std::size_t position) const noexcept {
return position < state_->parameters.size() ? state_->parameters[position] : parameter{}; return position < state_->arguments.size() ? state_->arguments[position] : argument{};
} }
inline const parameter_list& ctor::get_parameters() const noexcept { inline const argument_list& constructor::get_arguments() const noexcept {
return state_->parameters; return state_->arguments;
} }
} }

View File

@@ -9,14 +9,14 @@
#include "../meta_base.hpp" #include "../meta_base.hpp"
#include "../meta_states.hpp" #include "../meta_states.hpp"
#include "../meta_types/dtor_type.hpp" #include "../meta_types/destructor_type.hpp"
#include "../meta_detail/value_utilities/uarg.hpp" #include "../meta_detail/value_utilities/uarg.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class > template < class_kind Class >
void raw_dtor_invoke(const uarg& ptr) { void raw_destructor_invoke(const uarg& ptr) {
using dt = dtor_traits<Class>; using dt = destructor_traits<Class>;
using class_type = typename dt::class_type; using class_type = typename dt::class_type;
if ( !ptr.can_cast_to<class_type*>() ) { if ( !ptr.can_cast_to<class_type*>() ) {
@@ -30,8 +30,8 @@ namespace meta_hpp::detail
} }
template < class_kind Class > template < class_kind Class >
bool raw_dtor_is_invocable_with(const uarg_base& ptr) { bool raw_destructor_is_invocable_with(const uarg_base& ptr) {
using dt = dtor_traits<Class>; using dt = destructor_traits<Class>;
using class_type = typename dt::class_type; using class_type = typename dt::class_type;
return ptr.can_cast_to<class_type*>(); return ptr.can_cast_to<class_type*>();
@@ -41,70 +41,70 @@ namespace meta_hpp::detail
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class > template < class_kind Class >
dtor_state::invoke_impl make_dtor_invoke() { destructor_state::invoke_impl make_destructor_invoke() {
return &raw_dtor_invoke<Class>; return &raw_destructor_invoke<Class>;
} }
template < class_kind Class > template < class_kind Class >
dtor_state::is_invocable_with_impl make_dtor_is_invocable_with() { destructor_state::is_invocable_with_impl make_destructor_is_invocable_with() {
return &raw_dtor_is_invocable_with<Class>; return &raw_destructor_is_invocable_with<Class>;
} }
} }
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class > template < class_kind Class >
dtor_state_ptr dtor_state::make() { destructor_state_ptr destructor_state::make() {
return std::make_shared<dtor_state>(dtor_state{ return std::make_shared<destructor_state>(destructor_state{
.index{dtor_index::make<Class>()}, .index{destructor_index::make<Class>()},
.invoke{make_dtor_invoke<Class>()}, .invoke{make_destructor_invoke<Class>()},
.is_invocable_with{make_dtor_is_invocable_with<Class>()}, .is_invocable_with{make_destructor_is_invocable_with<Class>()},
}); });
} }
} }
namespace meta_hpp namespace meta_hpp
{ {
inline dtor::dtor(detail::dtor_state_ptr state) inline destructor::destructor(detail::destructor_state_ptr state)
: state_{std::move(state)} {} : state_{std::move(state)} {}
inline bool dtor::is_valid() const noexcept { inline bool destructor::is_valid() const noexcept {
return !!state_; return !!state_;
} }
inline dtor::operator bool() const noexcept { inline destructor::operator bool() const noexcept {
return is_valid(); return is_valid();
} }
inline const dtor_index& dtor::get_index() const noexcept { inline const destructor_index& destructor::get_index() const noexcept {
return state_->index; return state_->index;
} }
inline const dtor_type& dtor::get_type() const noexcept { inline const destructor_type& destructor::get_type() const noexcept {
return state_->index.get_type(); return state_->index.get_type();
} }
template < typename Arg > template < typename Arg >
void dtor::invoke(Arg&& ptr) const { void destructor::invoke(Arg&& ptr) const {
using namespace detail; using namespace detail;
const uarg varg{std::forward<Arg>(ptr)}; const uarg varg{std::forward<Arg>(ptr)};
state_->invoke(varg); state_->invoke(varg);
} }
template < typename Arg > template < typename Arg >
void dtor::operator()(Arg&& ptr) const { void destructor::operator()(Arg&& ptr) const {
invoke(std::forward<Arg>(ptr)); invoke(std::forward<Arg>(ptr));
} }
template < typename Arg > template < typename Arg >
bool dtor::is_invocable_with() const noexcept { bool destructor::is_invocable_with() const noexcept {
using namespace detail; using namespace detail;
const uarg_base varg{type_list<Arg>{}}; const uarg_base varg{type_list<Arg>{}};
return state_->is_invocable_with(varg); return state_->is_invocable_with(varg);
} }
template < typename Arg > template < typename Arg >
bool dtor::is_invocable_with(Arg&& ptr) const noexcept { bool destructor::is_invocable_with(Arg&& ptr) const noexcept {
using namespace detail; using namespace detail;
const uarg_base varg{std::forward<Arg>(ptr)}; const uarg_base varg{std::forward<Arg>(ptr)};
return state_->is_invocable_with(varg); return state_->is_invocable_with(varg);

View File

@@ -96,21 +96,21 @@ namespace meta_hpp::detail
} }
template < function_kind Function > template < function_kind Function >
parameter_list make_function_parameters() { argument_list make_function_arguments() {
using ft = detail::function_traits<Function>; using ft = detail::function_traits<Function>;
parameter_list parameters; argument_list arguments;
parameters.reserve(ft::arity); arguments.reserve(ft::arity);
// NOLINTNEXTLINE(readability-named-parameter) // NOLINTNEXTLINE(readability-named-parameter)
[&parameters]<std::size_t... Is>(std::index_sequence<Is...>) mutable { [&arguments]<std::size_t... Is>(std::index_sequence<Is...>) mutable {
(parameters.push_back([]<std::size_t I>(){ (arguments.push_back([]<std::size_t I>(){
using P = detail::type_list_at_t<I, typename ft::argument_types>; using P = detail::type_list_at_t<I, typename ft::argument_types>;
return parameter{detail::parameter_state::make<P>(I)}; return argument{detail::argument_state::make<P>(I)};
}.template operator()<Is>()), ...); }.template operator()<Is>()), ...);
}(std::make_index_sequence<ft::arity>()); }(std::make_index_sequence<ft::arity>());
return parameters; return arguments;
} }
} }
@@ -122,7 +122,7 @@ namespace meta_hpp::detail
.index{function_index::make<Function>(std::move(name))}, .index{function_index::make<Function>(std::move(name))},
.invoke{make_function_invoke<Policy>(std::move(function))}, .invoke{make_function_invoke<Policy>(std::move(function))},
.is_invocable_with{make_function_is_invocable_with<Function>()}, .is_invocable_with{make_function_is_invocable_with<Function>()},
.parameters{make_function_parameters<Function>()}, .arguments{make_function_arguments<Function>()},
}); });
} }
} }
@@ -190,11 +190,11 @@ namespace meta_hpp
} }
} }
inline parameter function::get_parameter(std::size_t position) const noexcept { inline argument function::get_argument(std::size_t position) const noexcept {
return position < state_->parameters.size() ? state_->parameters[position] : parameter{}; return position < state_->arguments.size() ? state_->arguments[position] : argument{};
} }
inline const parameter_list& function::get_parameters() const noexcept { inline const argument_list& function::get_arguments() const noexcept {
return state_->parameters; return state_->arguments;
} }
} }

View File

@@ -109,21 +109,21 @@ namespace meta_hpp::detail
} }
template < method_kind Method > template < method_kind Method >
parameter_list make_method_parameters() { argument_list make_method_arguments() {
using mt = detail::method_traits<Method>; using mt = detail::method_traits<Method>;
parameter_list parameters; argument_list arguments;
parameters.reserve(mt::arity); arguments.reserve(mt::arity);
// NOLINTNEXTLINE(readability-named-parameter) // NOLINTNEXTLINE(readability-named-parameter)
[&parameters]<std::size_t... Is>(std::index_sequence<Is...>) mutable { [&arguments]<std::size_t... Is>(std::index_sequence<Is...>) mutable {
(parameters.push_back([]<std::size_t I>(){ (arguments.push_back([]<std::size_t I>(){
using P = detail::type_list_at_t<I, typename mt::argument_types>; using P = detail::type_list_at_t<I, typename mt::argument_types>;
return parameter{detail::parameter_state::make<P>(I)}; return argument{detail::argument_state::make<P>(I)};
}.template operator()<Is>()), ...); }.template operator()<Is>()), ...);
}(std::make_index_sequence<mt::arity>()); }(std::make_index_sequence<mt::arity>());
return parameters; return arguments;
} }
} }
@@ -135,7 +135,7 @@ namespace meta_hpp::detail
.index{method_index::make<Method>(std::move(name))}, .index{method_index::make<Method>(std::move(name))},
.invoke{make_method_invoke<Policy>(std::move(method))}, .invoke{make_method_invoke<Policy>(std::move(method))},
.is_invocable_with{make_method_is_invocable_with<Method>()}, .is_invocable_with{make_method_is_invocable_with<Method>()},
.parameters{make_method_parameters<Method>()}, .arguments{make_method_arguments<Method>()},
}); });
} }
} }
@@ -206,11 +206,11 @@ namespace meta_hpp
} }
} }
inline parameter method::get_parameter(std::size_t position) const noexcept { inline argument method::get_argument(std::size_t position) const noexcept {
return position < state_->parameters.size() ? state_->parameters[position] : parameter{}; return position < state_->arguments.size() ? state_->arguments[position] : argument{};
} }
inline const parameter_list& method::get_parameters() const noexcept { inline const argument_list& method::get_arguments() const noexcept {
return state_->parameters; return state_->arguments;
} }
} }

View File

@@ -12,8 +12,8 @@
#include "meta_detail/type_traits/array_traits.hpp" #include "meta_detail/type_traits/array_traits.hpp"
#include "meta_detail/type_traits/class_traits.hpp" #include "meta_detail/type_traits/class_traits.hpp"
#include "meta_detail/type_traits/ctor_traits.hpp" #include "meta_detail/type_traits/constructor_traits.hpp"
#include "meta_detail/type_traits/dtor_traits.hpp" #include "meta_detail/type_traits/destructor_traits.hpp"
#include "meta_detail/type_traits/enum_traits.hpp" #include "meta_detail/type_traits/enum_traits.hpp"
#include "meta_detail/type_traits/function_traits.hpp" #include "meta_detail/type_traits/function_traits.hpp"
#include "meta_detail/type_traits/member_traits.hpp" #include "meta_detail/type_traits/member_traits.hpp"
@@ -30,11 +30,11 @@ namespace meta_hpp
using class_flags = detail::class_flags; using class_flags = detail::class_flags;
using class_bitflags = detail::class_bitflags; using class_bitflags = detail::class_bitflags;
using ctor_flags = detail::ctor_flags; using constructor_flags = detail::constructor_flags;
using ctor_bitflags = detail::ctor_bitflags; using constructor_bitflags = detail::constructor_bitflags;
using dtor_flags = detail::dtor_flags; using destructor_flags = detail::destructor_flags;
using dtor_bitflags = detail::dtor_bitflags; using destructor_bitflags = detail::destructor_bitflags;
using enum_flags = detail::enum_flags; using enum_flags = detail::enum_flags;
using enum_bitflags = detail::enum_bitflags; using enum_bitflags = detail::enum_bitflags;
@@ -72,8 +72,8 @@ namespace meta_hpp
any_type(const array_type& other) noexcept; any_type(const array_type& other) noexcept;
any_type(const class_type& other) noexcept; any_type(const class_type& other) noexcept;
any_type(const ctor_type& other) noexcept; any_type(const constructor_type& other) noexcept;
any_type(const dtor_type& other) noexcept; any_type(const destructor_type& other) noexcept;
any_type(const enum_type& other) noexcept; any_type(const enum_type& other) noexcept;
any_type(const function_type& other) noexcept; any_type(const function_type& other) noexcept;
any_type(const member_type& other) noexcept; any_type(const member_type& other) noexcept;
@@ -86,8 +86,8 @@ namespace meta_hpp
[[nodiscard]] bool is_array() const noexcept; [[nodiscard]] bool is_array() const noexcept;
[[nodiscard]] bool is_class() const noexcept; [[nodiscard]] bool is_class() const noexcept;
[[nodiscard]] bool is_ctor() const noexcept; [[nodiscard]] bool is_constructor() const noexcept;
[[nodiscard]] bool is_dtor() const noexcept; [[nodiscard]] bool is_destructor() const noexcept;
[[nodiscard]] bool is_enum() const noexcept; [[nodiscard]] bool is_enum() const noexcept;
[[nodiscard]] bool is_function() const noexcept; [[nodiscard]] bool is_function() const noexcept;
[[nodiscard]] bool is_member() const noexcept; [[nodiscard]] bool is_member() const noexcept;
@@ -100,8 +100,8 @@ namespace meta_hpp
[[nodiscard]] array_type as_array() const noexcept; [[nodiscard]] array_type as_array() const noexcept;
[[nodiscard]] class_type as_class() const noexcept; [[nodiscard]] class_type as_class() const noexcept;
[[nodiscard]] ctor_type as_ctor() const noexcept; [[nodiscard]] constructor_type as_constructor() const noexcept;
[[nodiscard]] dtor_type as_dtor() const noexcept; [[nodiscard]] destructor_type as_destructor() const noexcept;
[[nodiscard]] enum_type as_enum() const noexcept; [[nodiscard]] enum_type as_enum() const noexcept;
[[nodiscard]] function_type as_function() const noexcept; [[nodiscard]] function_type as_function() const noexcept;
[[nodiscard]] member_type as_member() const noexcept; [[nodiscard]] member_type as_member() const noexcept;
@@ -151,8 +151,8 @@ namespace meta_hpp
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
[[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept; [[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept;
[[nodiscard]] const ctor_map& get_ctors() const noexcept; [[nodiscard]] const constructor_map& get_ctors() const noexcept;
[[nodiscard]] const dtor_map& get_dtors() const noexcept; [[nodiscard]] const destructor_map& get_dtors() const noexcept;
[[nodiscard]] const class_set& get_bases() const noexcept; [[nodiscard]] const class_set& get_bases() const noexcept;
[[nodiscard]] const function_map& get_functions() const noexcept; [[nodiscard]] const function_map& get_functions() const noexcept;
[[nodiscard]] const member_map& get_members() const noexcept; [[nodiscard]] const member_map& get_members() const noexcept;
@@ -182,11 +182,11 @@ namespace meta_hpp
[[nodiscard]] variable get_variable(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] ctor get_ctor_with() const noexcept; [[nodiscard]] constructor get_constructor_with() const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] ctor get_ctor_with(Iter first, Iter last) const noexcept; [[nodiscard]] constructor get_constructor_with(Iter first, Iter last) const noexcept;
[[nodiscard]] ctor get_ctor_with(const std::vector<any_type>& args) const noexcept; [[nodiscard]] constructor get_constructor_with(const std::vector<any_type>& args) const noexcept;
[[nodiscard]] ctor get_ctor_with(std::initializer_list<any_type> args) const noexcept; [[nodiscard]] constructor get_constructor_with(std::initializer_list<any_type> args) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] function get_function_with(std::string_view name) const noexcept; [[nodiscard]] function get_function_with(std::string_view name) const noexcept;
@@ -206,41 +206,41 @@ namespace meta_hpp
friend auto detail::type_access<class_type>(const class_type&); friend auto detail::type_access<class_type>(const class_type&);
}; };
class ctor_type final { class constructor_type final {
public: public:
ctor_type() = default; constructor_type() = default;
ctor_type(detail::ctor_type_data_ptr data); constructor_type(detail::constructor_type_data_ptr data);
[[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept; [[nodiscard]] type_id get_id() const noexcept;
[[nodiscard]] ctor_bitflags get_flags() const noexcept; [[nodiscard]] constructor_bitflags get_flags() const noexcept;
[[nodiscard]] std::size_t get_arity() const noexcept; [[nodiscard]] std::size_t get_arity() const noexcept;
[[nodiscard]] any_type get_class_type() const noexcept; [[nodiscard]] any_type get_class_type() const noexcept;
[[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept;
[[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept; [[nodiscard]] const std::vector<any_type>& get_argument_types() const noexcept;
private: private:
detail::ctor_type_data_ptr data_; detail::constructor_type_data_ptr data_;
friend auto detail::type_access<ctor_type>(const ctor_type&); friend auto detail::type_access<constructor_type>(const constructor_type&);
}; };
class dtor_type final { class destructor_type final {
public: public:
dtor_type() = default; destructor_type() = default;
dtor_type(detail::dtor_type_data_ptr data); destructor_type(detail::destructor_type_data_ptr data);
[[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] bool is_valid() const noexcept;
[[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] explicit operator bool() const noexcept;
[[nodiscard]] type_id get_id() const noexcept; [[nodiscard]] type_id get_id() const noexcept;
[[nodiscard]] dtor_bitflags get_flags() const noexcept; [[nodiscard]] destructor_bitflags get_flags() const noexcept;
[[nodiscard]] any_type get_class_type() const noexcept; [[nodiscard]] any_type get_class_type() const noexcept;
private: private:
detail::dtor_type_data_ptr data_; detail::destructor_type_data_ptr data_;
friend auto detail::type_access<dtor_type>(const dtor_type&); friend auto detail::type_access<destructor_type>(const destructor_type&);
}; };
class enum_type final { class enum_type final {
@@ -466,8 +466,8 @@ namespace meta_hpp::detail
const std::size_t size; const std::size_t size;
const std::vector<any_type> argument_types; const std::vector<any_type> argument_types;
ctor_map ctors; constructor_map constructors;
dtor_map dtors; destructor_map destructors;
class_set bases; class_set bases;
function_map functions; function_map functions;
member_map members; member_map members;
@@ -486,21 +486,21 @@ namespace meta_hpp::detail
explicit class_type_data(type_list<Class>); explicit class_type_data(type_list<Class>);
}; };
struct ctor_type_data final : type_data_base { struct constructor_type_data final : type_data_base {
const ctor_bitflags flags; const constructor_bitflags flags;
const any_type class_type; const any_type class_type;
const std::vector<any_type> argument_types; const std::vector<any_type> argument_types;
template < class_kind Class, typename... Args > template < class_kind Class, typename... Args >
explicit ctor_type_data(type_list<Class>, type_list<Args...>); explicit constructor_type_data(type_list<Class>, type_list<Args...>);
}; };
struct dtor_type_data final : type_data_base { struct destructor_type_data final : type_data_base {
const dtor_bitflags flags; const destructor_bitflags flags;
const any_type class_type; const any_type class_type;
template < class_kind Class > template < class_kind Class >
explicit dtor_type_data(type_list<Class>); explicit destructor_type_data(type_list<Class>);
}; };
struct enum_type_data final : type_data_base { struct enum_type_data final : type_data_base {

View File

@@ -33,10 +33,10 @@ namespace meta_hpp
inline any_type::any_type(const class_type& other) noexcept inline any_type::any_type(const class_type& other) noexcept
: data_{detail::type_access(other)} {} : data_{detail::type_access(other)} {}
inline any_type::any_type(const ctor_type& other) noexcept inline any_type::any_type(const constructor_type& other) noexcept
: data_{detail::type_access(other)} {} : data_{detail::type_access(other)} {}
inline any_type::any_type(const dtor_type& other) noexcept inline any_type::any_type(const destructor_type& other) noexcept
: data_{detail::type_access(other)} {} : data_{detail::type_access(other)} {}
inline any_type::any_type(const enum_type& other) noexcept inline any_type::any_type(const enum_type& other) noexcept
@@ -74,12 +74,12 @@ namespace meta_hpp
return data_ && data_->kind == type_kind::class_; return data_ && data_->kind == type_kind::class_;
} }
inline bool any_type::is_ctor() const noexcept { inline bool any_type::is_constructor() const noexcept {
return data_ && data_->kind == type_kind::ctor_; return data_ && data_->kind == type_kind::constructor_;
} }
inline bool any_type::is_dtor() const noexcept { inline bool any_type::is_destructor() const noexcept {
return data_ && data_->kind == type_kind::dtor_; return data_ && data_->kind == type_kind::destructor_;
} }
inline bool any_type::is_enum() const noexcept { inline bool any_type::is_enum() const noexcept {
@@ -130,16 +130,16 @@ namespace meta_hpp
: class_type{}; : class_type{};
} }
inline ctor_type any_type::as_ctor() const noexcept { inline constructor_type any_type::as_constructor() const noexcept {
return is_ctor() return is_constructor()
? ctor_type{std::static_pointer_cast<detail::ctor_type_data>(data_)} ? constructor_type{std::static_pointer_cast<detail::constructor_type_data>(data_)}
: ctor_type{}; : constructor_type{};
} }
inline dtor_type any_type::as_dtor() const noexcept { inline destructor_type any_type::as_destructor() const noexcept {
return is_dtor() return is_destructor()
? dtor_type{std::static_pointer_cast<detail::dtor_type_data>(data_)} ? destructor_type{std::static_pointer_cast<detail::destructor_type_data>(data_)}
: dtor_type{}; : destructor_type{};
} }
inline enum_type any_type::as_enum() const noexcept { inline enum_type any_type::as_enum() const noexcept {

View File

@@ -9,7 +9,7 @@
#include "../meta_base.hpp" #include "../meta_base.hpp"
#include "../meta_types.hpp" #include "../meta_types.hpp"
#include "../meta_states/ctor.hpp" #include "../meta_states/constructor.hpp"
#include "../meta_states/function.hpp" #include "../meta_states/function.hpp"
#include "../meta_states/member.hpp" #include "../meta_states/member.hpp"
#include "../meta_states/method.hpp" #include "../meta_states/method.hpp"
@@ -69,12 +69,12 @@ namespace meta_hpp
return data_->argument_types; return data_->argument_types;
} }
inline const ctor_map& class_type::get_ctors() const noexcept { inline const constructor_map& class_type::get_ctors() const noexcept {
return data_->ctors; return data_->constructors;
} }
inline const dtor_map& class_type::get_dtors() const noexcept { inline const destructor_map& class_type::get_dtors() const noexcept {
return data_->dtors; return data_->destructors;
} }
inline const class_set& class_type::get_bases() const noexcept { inline const class_set& class_type::get_bases() const noexcept {
@@ -99,7 +99,7 @@ namespace meta_hpp
template < typename... Args > template < typename... Args >
uvalue class_type::create(Args&&... args) const { uvalue class_type::create(Args&&... args) const {
for ( auto&& ctor : data_->ctors ) { for ( auto&& ctor : data_->constructors ) {
if ( ctor.second.is_invocable_with(std::forward<Args>(args)...) ) { if ( ctor.second.is_invocable_with(std::forward<Args>(args)...) ) {
return ctor.second.invoke(std::forward<Args>(args)...); return ctor.second.invoke(std::forward<Args>(args)...);
} }
@@ -114,7 +114,7 @@ namespace meta_hpp
template < typename Arg > template < typename Arg >
bool class_type::destroy(Arg&& ptr) const { bool class_type::destroy(Arg&& ptr) const {
for ( auto&& dtor : data_->dtors ) { for ( auto&& dtor : data_->destructors ) {
if ( dtor.second.is_invocable_with(std::forward<Arg>(ptr)) ) { if ( dtor.second.is_invocable_with(std::forward<Arg>(ptr)) ) {
dtor.second.invoke(std::forward<Arg>(ptr)); dtor.second.invoke(std::forward<Arg>(ptr));
return true; return true;
@@ -234,31 +234,31 @@ namespace meta_hpp
} }
// //
// get_ctor_with // get_constructor_with
// //
template < typename... Args > template < typename... Args >
ctor class_type::get_ctor_with() const noexcept { constructor class_type::get_constructor_with() const noexcept {
return get_ctor_with({detail::resolve_type<Args>()...}); return get_constructor_with({detail::resolve_type<Args>()...});
} }
template < typename Iter > template < typename Iter >
ctor class_type::get_ctor_with(Iter first, Iter last) const noexcept { constructor class_type::get_constructor_with(Iter first, Iter last) const noexcept {
for ( auto&& [index, ctor] : data_->ctors ) { for ( auto&& [index, ctor] : data_->constructors ) {
const std::vector<any_type>& args = ctor.get_type().get_argument_types(); const std::vector<any_type>& args = ctor.get_type().get_argument_types();
if ( std::equal(first, last, args.begin(), args.end()) ) { if ( std::equal(first, last, args.begin(), args.end()) ) {
return ctor; return ctor;
} }
} }
return ctor{}; return constructor{};
} }
inline ctor class_type::get_ctor_with(const std::vector<any_type>& args) const noexcept { inline constructor class_type::get_constructor_with(const std::vector<any_type>& args) const noexcept {
return get_ctor_with(args.begin(), args.end()); return get_constructor_with(args.begin(), args.end());
} }
inline ctor class_type::get_ctor_with(std::initializer_list<any_type> args) const noexcept { inline constructor class_type::get_constructor_with(std::initializer_list<any_type> args) const noexcept {
return get_ctor_with(args.begin(), args.end()); return get_constructor_with(args.begin(), args.end());
} }
// //

View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "../meta_base.hpp"
#include "../meta_types.hpp"
#include "../meta_detail/type_registry.hpp"
#include "../meta_detail/type_traits/constructor_traits.hpp"
namespace meta_hpp::detail
{
template < class_kind Class, typename... Args >
struct constructor_tag {};
template < class_kind Class, typename... Args >
// NOLINTNEXTLINE(readability-named-parameter)
constructor_type_data::constructor_type_data(type_list<Class>, type_list<Args...>)
: type_data_base{type_id{type_list<constructor_tag<Class, Args...>>{}}, type_kind::constructor_}
, flags{constructor_traits<Class, Args...>::make_flags()}
, class_type{resolve_type<typename constructor_traits<Class, Args...>::class_type>()}
, argument_types{resolve_types(typename constructor_traits<Class, Args...>::argument_types{})} {}
}
namespace meta_hpp
{
inline constructor_type::constructor_type(detail::constructor_type_data_ptr data)
: data_{std::move(data)} {}
inline bool constructor_type::is_valid() const noexcept {
return !!data_;
}
inline constructor_type::operator bool() const noexcept {
return is_valid();
}
inline type_id constructor_type::get_id() const noexcept {
return data_->id;
}
inline constructor_bitflags constructor_type::get_flags() const noexcept {
return data_->flags;
}
inline std::size_t constructor_type::get_arity() const noexcept {
return data_->argument_types.size();
}
inline any_type constructor_type::get_class_type() const noexcept {
return data_->class_type;
}
inline any_type constructor_type::get_argument_type(std::size_t position) const noexcept {
return position < data_->argument_types.size() ? data_->argument_types[position] : any_type{};
}
inline const std::vector<any_type>& constructor_type::get_argument_types() const noexcept {
return data_->argument_types;
}
}

View File

@@ -1,65 +0,0 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/meta.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "../meta_base.hpp"
#include "../meta_types.hpp"
#include "../meta_detail/type_registry.hpp"
#include "../meta_detail/type_traits/ctor_traits.hpp"
namespace meta_hpp::detail
{
template < class_kind Class, typename... Args >
struct ctor_tag {};
template < class_kind Class, typename... Args >
// NOLINTNEXTLINE(readability-named-parameter)
ctor_type_data::ctor_type_data(type_list<Class>, type_list<Args...>)
: type_data_base{type_id{type_list<ctor_tag<Class, Args...>>{}}, type_kind::ctor_}
, flags{ctor_traits<Class, Args...>::make_flags()}
, class_type{resolve_type<typename ctor_traits<Class, Args...>::class_type>()}
, argument_types{resolve_types(typename ctor_traits<Class, Args...>::argument_types{})} {}
}
namespace meta_hpp
{
inline ctor_type::ctor_type(detail::ctor_type_data_ptr data)
: data_{std::move(data)} {}
inline bool ctor_type::is_valid() const noexcept {
return !!data_;
}
inline ctor_type::operator bool() const noexcept {
return is_valid();
}
inline type_id ctor_type::get_id() const noexcept {
return data_->id;
}
inline ctor_bitflags ctor_type::get_flags() const noexcept {
return data_->flags;
}
inline std::size_t ctor_type::get_arity() const noexcept {
return data_->argument_types.size();
}
inline any_type ctor_type::get_class_type() const noexcept {
return data_->class_type;
}
inline any_type ctor_type::get_argument_type(std::size_t position) const noexcept {
return position < data_->argument_types.size() ? data_->argument_types[position] : any_type{};
}
inline const std::vector<any_type>& ctor_type::get_argument_types() const noexcept {
return data_->argument_types;
}
}

View File

@@ -10,43 +10,43 @@
#include "../meta_types.hpp" #include "../meta_types.hpp"
#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_registry.hpp"
#include "../meta_detail/type_traits/dtor_traits.hpp" #include "../meta_detail/type_traits/destructor_traits.hpp"
namespace meta_hpp::detail namespace meta_hpp::detail
{ {
template < class_kind Class > template < class_kind Class >
struct dtor_tag {}; struct destructor_tag {};
template < class_kind Class > template < class_kind Class >
// NOLINTNEXTLINE(readability-named-parameter) // NOLINTNEXTLINE(readability-named-parameter)
dtor_type_data::dtor_type_data(type_list<Class>) destructor_type_data::destructor_type_data(type_list<Class>)
: type_data_base{type_id{type_list<dtor_tag<Class>>{}}, type_kind::dtor_} : type_data_base{type_id{type_list<destructor_tag<Class>>{}}, type_kind::destructor_}
, flags{dtor_traits<Class>::make_flags()} , flags{destructor_traits<Class>::make_flags()}
, class_type{resolve_type<typename dtor_traits<Class>::class_type>()} {} , class_type{resolve_type<typename destructor_traits<Class>::class_type>()} {}
} }
namespace meta_hpp namespace meta_hpp
{ {
inline dtor_type::dtor_type(detail::dtor_type_data_ptr data) inline destructor_type::destructor_type(detail::destructor_type_data_ptr data)
: data_{std::move(data)} {} : data_{std::move(data)} {}
inline bool dtor_type::is_valid() const noexcept { inline bool destructor_type::is_valid() const noexcept {
return !!data_; return !!data_;
} }
inline dtor_type::operator bool() const noexcept { inline destructor_type::operator bool() const noexcept {
return is_valid(); return is_valid();
} }
inline type_id dtor_type::get_id() const noexcept { inline type_id destructor_type::get_id() const noexcept {
return data_->id; return data_->id;
} }
inline dtor_bitflags dtor_type::get_flags() const noexcept { inline destructor_bitflags destructor_type::get_flags() const noexcept {
return data_->flags; return data_->flags;
} }
inline any_type dtor_type::get_class_type() const noexcept { inline any_type destructor_type::get_class_type() const noexcept {
return data_->class_type; return data_->class_type;
} }
} }

View File

@@ -47,7 +47,7 @@ TEST_CASE("meta/meta_examples/classes/type") {
// 'rectangle' class type registration // 'rectangle' class type registration
meta::class_<rectangle>() meta::class_<rectangle>()
.base_<shape>() .base_<shape>()
.ctor_<int, int>() .constructor_<int, int>()
.method_("get_width", &rectangle::get_width) .method_("get_width", &rectangle::get_width)
.method_("get_height", &rectangle::get_height); .method_("get_height", &rectangle::get_height);

View File

@@ -54,7 +54,7 @@ TEST_CASE("meta/meta_examples/functions/usage") {
// checks a type of the founded function // checks a type of the founded function
CHECK(sub_function.get_type() == meta::resolve_type<int(*)(int, int)>()); CHECK(sub_function.get_type() == meta::resolve_type<int(*)(int, int)>());
// checks the ability to call the function with specific parameters // checks the ability to call the function with specific arguments
CHECK(sub_function.is_invocable_with(60, 18)); CHECK(sub_function.is_invocable_with(60, 18));
CHECK(sub_function.is_invocable_with<int, int>()); CHECK(sub_function.is_invocable_with<int, int>());

View File

@@ -64,7 +64,7 @@ TEST_CASE("meta/meta_examples/methods/usage") {
// checks the type of the method 'add' // checks the type of the method 'add'
CHECK(ivec2_add.get_type() == meta::resolve_type<ivec2&(ivec2::*)(const ivec2&)>()); CHECK(ivec2_add.get_type() == meta::resolve_type<ivec2&(ivec2::*)(const ivec2&)>());
// checks the ability to call the method with specific parameters // checks the ability to call the method with specific arguments
CHECK(ivec2_add.is_invocable_with(v, ivec2{22, 11})); CHECK(ivec2_add.is_invocable_with(v, ivec2{22, 11}));
CHECK(ivec2_add.is_invocable_with<ivec2&, ivec2>()); CHECK(ivec2_add.is_invocable_with<ivec2&, ivec2>());

View File

@@ -14,75 +14,75 @@ namespace
clazz(int i) clazz(int i)
: i{i} { : i{i} {
++ctor_counter; ++constructor_counter;
} }
clazz(clazz&& other) clazz(clazz&& other)
: i{other.i} { : i{other.i} {
other.i = 0; other.i = 0;
++move_ctor_counter; ++move_constructor_counter;
} }
clazz(const clazz& other) clazz(const clazz& other)
: i{other.i} { : i{other.i} {
++copy_ctor_counter; ++copy_constructor_counter;
} }
clazz& operator=(clazz&& other) = delete; clazz& operator=(clazz&& other) = delete;
clazz& operator=(const clazz& other) = delete; clazz& operator=(const clazz& other) = delete;
~clazz() { ~clazz() {
++dtor_counter; ++destructor_counter;
} }
public: public:
static int ctor_counter; static int constructor_counter;
static int dtor_counter; static int destructor_counter;
static int move_ctor_counter; static int move_constructor_counter;
static int copy_ctor_counter; static int copy_constructor_counter;
}; };
template < std::size_t N > template < std::size_t N >
int clazz<N>::ctor_counter{0}; int clazz<N>::constructor_counter{0};
template < std::size_t N > template < std::size_t N >
int clazz<N>::dtor_counter{0}; int clazz<N>::destructor_counter{0};
template < std::size_t N > template < std::size_t N >
int clazz<N>::move_ctor_counter{0}; int clazz<N>::move_constructor_counter{0};
template < std::size_t N > template < std::size_t N >
int clazz<N>::copy_ctor_counter{0}; int clazz<N>::copy_constructor_counter{0};
} }
TEST_CASE("meta/meta_states/ctor") { TEST_CASE("meta/meta_states/ctor") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
meta::class_<clazz<1>>() meta::class_<clazz<1>>()
.ctor_<int>(meta::ctor_policy::as_object{}) .constructor_<int>(meta::constructor_policy::as_object{})
.dtor_(); .destructor_();
meta::class_<clazz<2>>() meta::class_<clazz<2>>()
.ctor_<int>(meta::ctor_policy::as_raw_pointer{}) .constructor_<int>(meta::constructor_policy::as_raw_pointer{})
.dtor_(); .destructor_();
meta::class_<clazz<3>>() meta::class_<clazz<3>>()
.ctor_<int>(meta::ctor_policy::as_shared_pointer{}) .constructor_<int>(meta::constructor_policy::as_shared_pointer{})
.dtor_(); .destructor_();
clazz<1>::ctor_counter = 0; clazz<1>::constructor_counter = 0;
clazz<1>::dtor_counter = 0; clazz<1>::destructor_counter = 0;
clazz<1>::move_ctor_counter = 0; clazz<1>::move_constructor_counter = 0;
clazz<1>::copy_ctor_counter = 0; clazz<1>::copy_constructor_counter = 0;
clazz<2>::ctor_counter = 0; clazz<2>::constructor_counter = 0;
clazz<2>::dtor_counter = 0; clazz<2>::destructor_counter = 0;
clazz<2>::move_ctor_counter = 0; clazz<2>::move_constructor_counter = 0;
clazz<2>::copy_ctor_counter = 0; clazz<2>::copy_constructor_counter = 0;
clazz<3>::ctor_counter = 0; clazz<3>::constructor_counter = 0;
clazz<3>::dtor_counter = 0; clazz<3>::destructor_counter = 0;
clazz<3>::move_ctor_counter = 0; clazz<3>::move_constructor_counter = 0;
clazz<3>::copy_ctor_counter = 0; clazz<3>::copy_constructor_counter = 0;
SUBCASE("clazz<1>") { SUBCASE("clazz<1>") {
const meta::class_type clazz_type = meta::resolve_type<clazz<1>>(); const meta::class_type clazz_type = meta::resolve_type<clazz<1>>();
@@ -98,10 +98,10 @@ TEST_CASE("meta/meta_states/ctor") {
CHECK(clazz_type.destroy(meta::uvalue{nullptr})); CHECK(clazz_type.destroy(meta::uvalue{nullptr}));
} }
CHECK(clazz<1>::ctor_counter == 1); CHECK(clazz<1>::constructor_counter == 1);
CHECK(clazz<1>::dtor_counter == 2); CHECK(clazz<1>::destructor_counter == 2);
CHECK(clazz<1>::move_ctor_counter == 1); CHECK(clazz<1>::move_constructor_counter == 1);
CHECK(clazz<1>::copy_ctor_counter == 0); CHECK(clazz<1>::copy_constructor_counter == 0);
} }
SUBCASE("clazz<2>") { SUBCASE("clazz<2>") {
@@ -119,10 +119,10 @@ TEST_CASE("meta/meta_states/ctor") {
CHECK(clazz_type.destroy(meta::uvalue{nullptr})); CHECK(clazz_type.destroy(meta::uvalue{nullptr}));
} }
CHECK(clazz<2>::ctor_counter == 1); CHECK(clazz<2>::constructor_counter == 1);
CHECK(clazz<2>::dtor_counter == 1); CHECK(clazz<2>::destructor_counter == 1);
CHECK(clazz<2>::move_ctor_counter == 0); CHECK(clazz<2>::move_constructor_counter == 0);
CHECK(clazz<2>::copy_ctor_counter == 0); CHECK(clazz<2>::copy_constructor_counter == 0);
} }
SUBCASE("clazz<3>") { SUBCASE("clazz<3>") {
@@ -139,9 +139,9 @@ TEST_CASE("meta/meta_states/ctor") {
CHECK(clazz_type.destroy(meta::uvalue{nullptr})); CHECK(clazz_type.destroy(meta::uvalue{nullptr}));
} }
CHECK(clazz<3>::ctor_counter == 1); CHECK(clazz<3>::constructor_counter == 1);
CHECK(clazz<3>::dtor_counter == 1); CHECK(clazz<3>::destructor_counter == 1);
CHECK(clazz<3>::move_ctor_counter == 0); CHECK(clazz<3>::move_constructor_counter == 0);
CHECK(clazz<3>::copy_ctor_counter == 0); CHECK(clazz<3>::copy_constructor_counter == 0);
} }
} }

View File

@@ -36,37 +36,37 @@ TEST_CASE("meta/meta_states/function2") {
const meta::function func = ivec2_type.get_function("iadd"); const meta::function func = ivec2_type.get_function("iadd");
REQUIRE(func); REQUIRE(func);
CHECK(func.get_parameters().size() == 2); CHECK(func.get_arguments().size() == 2);
REQUIRE(func.get_parameter(0)); REQUIRE(func.get_argument(0));
CHECK(func.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>()); CHECK(func.get_argument(0).get_type() == meta::resolve_type<const ivec2&>());
CHECK(func.get_parameter(0).get_position() == 0); CHECK(func.get_argument(0).get_position() == 0);
CHECK(func.get_parameter(0).get_name() == "l"); CHECK(func.get_argument(0).get_name() == "l");
REQUIRE(func.get_parameter(1)); REQUIRE(func.get_argument(1));
CHECK(func.get_parameter(1).get_type() == meta::resolve_type<const ivec2&>()); CHECK(func.get_argument(1).get_type() == meta::resolve_type<const ivec2&>());
CHECK(func.get_parameter(1).get_position() == 1); CHECK(func.get_argument(1).get_position() == 1);
CHECK(func.get_parameter(1).get_name() == ""); CHECK(func.get_argument(1).get_name() == "");
CHECK_FALSE(func.get_parameter(2)); CHECK_FALSE(func.get_argument(2));
} }
SUBCASE("isub2") { SUBCASE("isub2") {
const meta::function func = ivec2_type.get_function("isub"); const meta::function func = ivec2_type.get_function("isub");
REQUIRE(func); REQUIRE(func);
REQUIRE(func.get_parameters().size() == 2); REQUIRE(func.get_arguments().size() == 2);
REQUIRE(func.get_parameter(0)); REQUIRE(func.get_argument(0));
CHECK(func.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>()); CHECK(func.get_argument(0).get_type() == meta::resolve_type<const ivec2&>());
CHECK(func.get_parameter(0).get_position() == 0); CHECK(func.get_argument(0).get_position() == 0);
CHECK(func.get_parameter(0).get_name() == "l"); CHECK(func.get_argument(0).get_name() == "l");
REQUIRE(func.get_parameter(1)); REQUIRE(func.get_argument(1));
CHECK(func.get_parameter(1).get_type() == meta::resolve_type<const ivec2&>()); CHECK(func.get_argument(1).get_type() == meta::resolve_type<const ivec2&>());
CHECK(func.get_parameter(1).get_position() == 1); CHECK(func.get_argument(1).get_position() == 1);
CHECK(func.get_parameter(1).get_name() == "r"); CHECK(func.get_argument(1).get_name() == "r");
CHECK_FALSE(func.get_parameter(2)); CHECK_FALSE(func.get_argument(2));
} }
} }

View File

@@ -33,13 +33,13 @@ TEST_CASE("meta/meta_states/method2") {
const meta::method add_m = ivec2_type.get_method("add"); const meta::method add_m = ivec2_type.get_method("add");
REQUIRE(add_m); REQUIRE(add_m);
CHECK(add_m.get_parameters().size() == 1); CHECK(add_m.get_arguments().size() == 1);
REQUIRE(add_m.get_parameter(0)); REQUIRE(add_m.get_argument(0));
CHECK(add_m.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>()); CHECK(add_m.get_argument(0).get_type() == meta::resolve_type<const ivec2&>());
CHECK(add_m.get_parameter(0).get_position() == 0); CHECK(add_m.get_argument(0).get_position() == 0);
CHECK(add_m.get_parameter(0).get_name() == "other"); CHECK(add_m.get_argument(0).get_name() == "other");
CHECK_FALSE(add_m.get_parameter(1)); CHECK_FALSE(add_m.get_argument(1));
} }
} }

View File

@@ -97,38 +97,38 @@ TEST_CASE("meta/meta_states/scope") {
REQUIRE(iadd2_func); REQUIRE(iadd2_func);
{ {
CHECK(iadd2_func.get_parameters().size() == 2); CHECK(iadd2_func.get_arguments().size() == 2);
REQUIRE(iadd2_func.get_parameter(0)); REQUIRE(iadd2_func.get_argument(0));
CHECK(iadd2_func.get_parameter(0).get_type() == meta::resolve_type<const ivec2&>()); CHECK(iadd2_func.get_argument(0).get_type() == meta::resolve_type<const ivec2&>());
CHECK(iadd2_func.get_parameter(0).get_position() == 0); CHECK(iadd2_func.get_argument(0).get_position() == 0);
CHECK(iadd2_func.get_parameter(0).get_name() == "l"); CHECK(iadd2_func.get_argument(0).get_name() == "l");
REQUIRE(iadd2_func.get_parameter(1)); REQUIRE(iadd2_func.get_argument(1));
CHECK(iadd2_func.get_parameter(1).get_type() == meta::resolve_type<const ivec2&>()); CHECK(iadd2_func.get_argument(1).get_type() == meta::resolve_type<const ivec2&>());
CHECK(iadd2_func.get_parameter(1).get_position() == 1); CHECK(iadd2_func.get_argument(1).get_position() == 1);
CHECK(iadd2_func.get_parameter(1).get_name() == "r"); CHECK(iadd2_func.get_argument(1).get_name() == "r");
CHECK_FALSE(iadd2_func.get_parameter(2)); CHECK_FALSE(iadd2_func.get_argument(2));
} }
const meta::function iadd3_func = math_scope.get_function("iadd3"); const meta::function iadd3_func = math_scope.get_function("iadd3");
REQUIRE(iadd3_func); REQUIRE(iadd3_func);
{ {
CHECK(iadd3_func.get_parameters().size() == 2); CHECK(iadd3_func.get_arguments().size() == 2);
REQUIRE(iadd3_func.get_parameter(0)); REQUIRE(iadd3_func.get_argument(0));
CHECK(iadd3_func.get_parameter(0).get_type() == meta::resolve_type<const ivec3&>()); CHECK(iadd3_func.get_argument(0).get_type() == meta::resolve_type<const ivec3&>());
CHECK(iadd3_func.get_parameter(0).get_position() == 0); CHECK(iadd3_func.get_argument(0).get_position() == 0);
CHECK(iadd3_func.get_parameter(0).get_name() == "l"); CHECK(iadd3_func.get_argument(0).get_name() == "l");
REQUIRE(iadd3_func.get_parameter(1)); REQUIRE(iadd3_func.get_argument(1));
CHECK(iadd3_func.get_parameter(1).get_type() == meta::resolve_type<const ivec3&>()); CHECK(iadd3_func.get_argument(1).get_type() == meta::resolve_type<const ivec3&>());
CHECK(iadd3_func.get_parameter(1).get_position() == 1); CHECK(iadd3_func.get_argument(1).get_position() == 1);
CHECK(iadd3_func.get_parameter(1).get_name() == ""); CHECK(iadd3_func.get_argument(1).get_name() == "");
CHECK_FALSE(iadd3_func.get_parameter(2)); CHECK_FALSE(iadd3_func.get_argument(2));
} }
} }

View File

@@ -32,8 +32,8 @@ TEST_CASE("meta/meta_types/any_type") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
meta::class_<class_t>() meta::class_<class_t>()
.ctor_<>() .constructor_<>()
.ctor_<int>(); .constructor_<int>();
SUBCASE("") { SUBCASE("") {
const meta::any_type type{}; const meta::any_type type{};
@@ -72,8 +72,8 @@ TEST_CASE("meta/meta_types/any_type") {
CHECK(type.is_class()); CHECK(type.is_class());
CHECK(type.get_kind() == meta::type_kind::class_); CHECK(type.get_kind() == meta::type_kind::class_);
CHECK_FALSE(type.is_ctor()); CHECK_FALSE(type.is_constructor());
CHECK_FALSE(type.as_ctor()); CHECK_FALSE(type.as_constructor());
const meta::class_type& specific_type = type.as_class(); const meta::class_type& specific_type = type.as_class();
REQUIRE(specific_type); REQUIRE(specific_type);
@@ -82,18 +82,18 @@ TEST_CASE("meta/meta_types/any_type") {
SUBCASE("ctor") { SUBCASE("ctor") {
const meta::any_type& type = meta::resolve_type<class_t>() const meta::any_type& type = meta::resolve_type<class_t>()
.get_ctor_with<>() .get_constructor_with<>()
.get_type(); .get_type();
REQUIRE(type); REQUIRE(type);
CHECK(type.is_ctor()); CHECK(type.is_constructor());
CHECK(type.get_kind() == meta::type_kind::ctor_); CHECK(type.get_kind() == meta::type_kind::constructor_);
CHECK_FALSE(type.is_enum()); CHECK_FALSE(type.is_enum());
CHECK_FALSE(type.as_enum()); CHECK_FALSE(type.as_enum());
const meta::ctor_type& specific_type = type.as_ctor(); const meta::constructor_type& specific_type = type.as_constructor();
REQUIRE(specific_type); REQUIRE(specific_type);
CHECK(specific_type.get_id() == type.get_id()); CHECK(specific_type.get_id() == type.get_id());
} }

View File

@@ -62,7 +62,7 @@ TEST_CASE("meta/meta_types/class_type") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
meta::class_<base_clazz_1>() meta::class_<base_clazz_1>()
.ctor_<int>() .constructor_<int>()
.member_("base_member_1", &base_clazz_1::base_member_1) .member_("base_member_1", &base_clazz_1::base_member_1)
.method_("base_method_1", &base_clazz_1::base_method_1) .method_("base_method_1", &base_clazz_1::base_method_1)
.function_("base_function_1", &base_clazz_1::base_function_1) .function_("base_function_1", &base_clazz_1::base_function_1)
@@ -73,14 +73,14 @@ TEST_CASE("meta/meta_types/class_type") {
.variable_("base_variable_1", &base_clazz_1::base_variable_1); .variable_("base_variable_1", &base_clazz_1::base_variable_1);
meta::class_<base_clazz_2>() meta::class_<base_clazz_2>()
.ctor_<float>() .constructor_<float>()
.member_("base_member_2", &base_clazz_2::base_member_2) .member_("base_member_2", &base_clazz_2::base_member_2)
.method_("base_method_2", &base_clazz_2::base_method_2) .method_("base_method_2", &base_clazz_2::base_method_2)
.function_("base_function_2", &base_clazz_2::base_function_2) .function_("base_function_2", &base_clazz_2::base_function_2)
.variable_("base_variable_2", &base_clazz_2::base_variable_2); .variable_("base_variable_2", &base_clazz_2::base_variable_2);
meta::class_<derived_clazz>() meta::class_<derived_clazz>()
.ctor_<int, float>() .constructor_<int, float>()
.base_<base_clazz_1>() .base_<base_clazz_1>()
.base_<base_clazz_2>() .base_<base_clazz_2>()
.member_("derived_member", &derived_clazz::derived_member) .member_("derived_member", &derived_clazz::derived_member)
@@ -89,7 +89,7 @@ TEST_CASE("meta/meta_types/class_type") {
.variable_("derived_variable", &derived_clazz::derived_variable); .variable_("derived_variable", &derived_clazz::derived_variable);
meta::class_<final_derived_clazz>() meta::class_<final_derived_clazz>()
.ctor_<int, float>() .constructor_<int, float>()
.base_<derived_clazz>(); .base_<derived_clazz>();
const meta::class_type base_clazz_1_type = meta::resolve_type<base_clazz_1>(); const meta::class_type base_clazz_1_type = meta::resolve_type<base_clazz_1>();
@@ -368,23 +368,23 @@ TEST_CASE("meta/meta_types/class_type") {
CHECK(derived_clazz_type.get_variable("derived_variable")); CHECK(derived_clazz_type.get_variable("derived_variable"));
} }
SUBCASE("get_ctor_with") { SUBCASE("get_constructor_with") {
{ {
CHECK_FALSE(base_clazz_1_type.get_ctor_with<>()); CHECK_FALSE(base_clazz_1_type.get_constructor_with<>());
CHECK(base_clazz_1_type.get_ctor_with<int>()); CHECK(base_clazz_1_type.get_constructor_with<int>());
CHECK_FALSE(base_clazz_1_type.get_ctor_with<float>()); CHECK_FALSE(base_clazz_1_type.get_constructor_with<float>());
} }
{ {
CHECK_FALSE(base_clazz_2_type.get_ctor_with<>()); CHECK_FALSE(base_clazz_2_type.get_constructor_with<>());
CHECK_FALSE(base_clazz_2_type.get_ctor_with<int>()); CHECK_FALSE(base_clazz_2_type.get_constructor_with<int>());
CHECK(base_clazz_2_type.get_ctor_with<float>()); CHECK(base_clazz_2_type.get_constructor_with<float>());
} }
{ {
CHECK_FALSE(derived_clazz_type.get_ctor_with<>()); CHECK_FALSE(derived_clazz_type.get_constructor_with<>());
CHECK_FALSE(derived_clazz_type.get_ctor_with<int>()); CHECK_FALSE(derived_clazz_type.get_constructor_with<int>());
CHECK_FALSE(derived_clazz_type.get_ctor_with<float>()); CHECK_FALSE(derived_clazz_type.get_constructor_with<float>());
CHECK(derived_clazz_type.get_ctor_with<int, float>()); CHECK(derived_clazz_type.get_constructor_with<int, float>());
CHECK_FALSE(derived_clazz_type.get_ctor_with<float, int>()); CHECK_FALSE(derived_clazz_type.get_constructor_with<float, int>());
} }
} }

View File

@@ -21,25 +21,25 @@ namespace
, y{other.y} { , y{other.y} {
other.x = 0; other.x = 0;
other.y = 0; other.y = 0;
++move_ctor_counter; ++move_constructor_counter;
} }
ivec2(const ivec2& other) noexcept ivec2(const ivec2& other) noexcept
: x{other.x} : x{other.x}
, y{other.y} { , y{other.y} {
++copy_ctor_counter; ++copy_constructor_counter;
} }
~ivec2() noexcept { ~ivec2() noexcept {
++dtor_counter; ++destructor_counter;
} }
ivec2& operator=(ivec2&& other) = delete; ivec2& operator=(ivec2&& other) = delete;
ivec2& operator=(const ivec2& other) = delete; ivec2& operator=(const ivec2& other) = delete;
static int dtor_counter; static int destructor_counter;
static int move_ctor_counter; static int move_constructor_counter;
static int copy_ctor_counter; static int copy_constructor_counter;
}; };
struct ivec2_big final { struct ivec2_big final {
@@ -57,25 +57,25 @@ namespace
, y{other.y} { , y{other.y} {
other.x = 0; other.x = 0;
other.y = 0; other.y = 0;
++move_ctor_counter; ++move_constructor_counter;
} }
ivec2_big(const ivec2_big& other) noexcept ivec2_big(const ivec2_big& other) noexcept
: x{other.x} : x{other.x}
, y{other.y} { , y{other.y} {
++copy_ctor_counter; ++copy_constructor_counter;
} }
~ivec2_big() noexcept { ~ivec2_big() noexcept {
++dtor_counter; ++destructor_counter;
} }
ivec2_big& operator=(ivec2_big&& other) = delete; ivec2_big& operator=(ivec2_big&& other) = delete;
ivec2_big& operator=(const ivec2_big& other) = delete; ivec2_big& operator=(const ivec2_big& other) = delete;
static int dtor_counter; static int destructor_counter;
static int move_ctor_counter; static int move_constructor_counter;
static int copy_ctor_counter; static int copy_constructor_counter;
}; };
[[maybe_unused]] bool operator==(const ivec2& l, const ivec2& r) noexcept { [[maybe_unused]] bool operator==(const ivec2& l, const ivec2& r) noexcept {
@@ -86,31 +86,31 @@ namespace
return l.x == r.x && l.y == r.y; return l.x == r.x && l.y == r.y;
} }
int ivec2::dtor_counter{0}; int ivec2::destructor_counter{0};
int ivec2::move_ctor_counter{0}; int ivec2::move_constructor_counter{0};
int ivec2::copy_ctor_counter{0}; int ivec2::copy_constructor_counter{0};
int ivec2_big::dtor_counter{0}; int ivec2_big::destructor_counter{0};
int ivec2_big::move_ctor_counter{0}; int ivec2_big::move_constructor_counter{0};
int ivec2_big::copy_ctor_counter{0}; int ivec2_big::copy_constructor_counter{0};
} }
TEST_CASE("meta/meta_utilities/value2") { TEST_CASE("meta/meta_utilities/value2") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
meta::class_<ivec2>() meta::class_<ivec2>()
.ctor_<int>() .constructor_<int>()
.ctor_<int, int>() .constructor_<int, int>()
.ctor_<ivec2&&>() .constructor_<ivec2&&>()
.ctor_<const ivec2&>() .constructor_<const ivec2&>()
.member_("x", &ivec2::x) .member_("x", &ivec2::x)
.member_("y", &ivec2::y); .member_("y", &ivec2::y);
meta::class_<ivec2_big>() meta::class_<ivec2_big>()
.ctor_<int>() .constructor_<int>()
.ctor_<int, int>() .constructor_<int, int>()
.ctor_<ivec2_big&&>() .constructor_<ivec2_big&&>()
.ctor_<const ivec2_big&>() .constructor_<const ivec2_big&>()
.member_("x", &ivec2_big::x) .member_("x", &ivec2_big::x)
.member_("y", &ivec2_big::y); .member_("y", &ivec2_big::y);
} }
@@ -118,32 +118,32 @@ TEST_CASE("meta/meta_utilities/value2") {
TEST_CASE("meta/meta_utilities/value2/counters/small") { TEST_CASE("meta/meta_utilities/value2/counters/small") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
ivec2::dtor_counter = 0; ivec2::destructor_counter = 0;
ivec2::move_ctor_counter = 0; ivec2::move_constructor_counter = 0;
ivec2::copy_ctor_counter = 0; ivec2::copy_constructor_counter = 0;
SUBCASE("def ctor") { SUBCASE("def ctor") {
{ {
meta::uvalue v{}; meta::uvalue v{};
CHECK(ivec2::dtor_counter == 0); CHECK(ivec2::destructor_counter == 0);
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
CHECK(ivec2::dtor_counter == 0); CHECK(ivec2::destructor_counter == 0);
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
SUBCASE("val ctor") { SUBCASE("val ctor") {
{ {
meta::uvalue v{ivec2{1,2}}; meta::uvalue v{ivec2{1,2}};
CHECK(ivec2::dtor_counter == 1); CHECK(ivec2::destructor_counter == 1);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
CHECK(ivec2::dtor_counter == 2); CHECK(ivec2::destructor_counter == 2);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
SUBCASE("move ctor") { SUBCASE("move ctor") {
@@ -154,13 +154,13 @@ TEST_CASE("meta/meta_utilities/value2/counters/small") {
CHECK_FALSE(v1); CHECK_FALSE(v1);
CHECK(v2.cast<ivec2>().x == 1); CHECK(v2.cast<ivec2>().x == 1);
CHECK(ivec2::dtor_counter == 2); CHECK(ivec2::destructor_counter == 2);
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
CHECK(ivec2::dtor_counter == 3); CHECK(ivec2::destructor_counter == 3);
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
SUBCASE("copy ctor") { SUBCASE("copy ctor") {
@@ -171,66 +171,66 @@ TEST_CASE("meta/meta_utilities/value2/counters/small") {
CHECK(v1.cast<ivec2>().x == 1); CHECK(v1.cast<ivec2>().x == 1);
CHECK(v2.cast<ivec2>().y == 2); CHECK(v2.cast<ivec2>().y == 2);
CHECK(ivec2::dtor_counter == 1); CHECK(ivec2::destructor_counter == 1);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
} }
CHECK(ivec2::dtor_counter == 3); CHECK(ivec2::destructor_counter == 3);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
} }
SUBCASE("swap") { SUBCASE("swap") {
{ {
meta::uvalue v1{ivec2{1,2}}; meta::uvalue v1{ivec2{1,2}};
meta::uvalue v2{ivec2{3,4}}; meta::uvalue v2{ivec2{3,4}};
CHECK(ivec2::dtor_counter == 2); CHECK(ivec2::destructor_counter == 2);
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK(v1.cast<ivec2>().x == 3); CHECK(v1.cast<ivec2>().x == 3);
CHECK(v2.cast<ivec2>().x == 1); CHECK(v2.cast<ivec2>().x == 1);
CHECK(ivec2::dtor_counter == 5); CHECK(ivec2::destructor_counter == 5);
CHECK(ivec2::move_ctor_counter == 5); CHECK(ivec2::move_constructor_counter == 5);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
CHECK(ivec2::dtor_counter == 7); CHECK(ivec2::destructor_counter == 7);
CHECK(ivec2::move_ctor_counter == 5); CHECK(ivec2::move_constructor_counter == 5);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
} }
TEST_CASE("meta/meta_utilities/value2/counters/big") { TEST_CASE("meta/meta_utilities/value2/counters/big") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
ivec2_big::dtor_counter = 0; ivec2_big::destructor_counter = 0;
ivec2_big::move_ctor_counter = 0; ivec2_big::move_constructor_counter = 0;
ivec2_big::copy_ctor_counter = 0; ivec2_big::copy_constructor_counter = 0;
SUBCASE("def ctor") { SUBCASE("def ctor") {
{ {
meta::uvalue v{}; meta::uvalue v{};
CHECK(ivec2_big::dtor_counter == 0); CHECK(ivec2_big::destructor_counter == 0);
CHECK(ivec2_big::move_ctor_counter == 0); CHECK(ivec2_big::move_constructor_counter == 0);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
CHECK(ivec2_big::dtor_counter == 0); CHECK(ivec2_big::destructor_counter == 0);
CHECK(ivec2_big::move_ctor_counter == 0); CHECK(ivec2_big::move_constructor_counter == 0);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
SUBCASE("val ctor") { SUBCASE("val ctor") {
{ {
meta::uvalue v{ivec2_big{1,2}}; meta::uvalue v{ivec2_big{1,2}};
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
CHECK(ivec2_big::dtor_counter == 2); CHECK(ivec2_big::destructor_counter == 2);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
SUBCASE("move ctor") { SUBCASE("move ctor") {
@@ -241,13 +241,13 @@ TEST_CASE("meta/meta_utilities/value2/counters/big") {
CHECK_FALSE(v1); CHECK_FALSE(v1);
CHECK(v2.cast<ivec2_big>().x == 1); CHECK(v2.cast<ivec2_big>().x == 1);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
CHECK(ivec2_big::dtor_counter == 2); CHECK(ivec2_big::destructor_counter == 2);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
SUBCASE("copy ctor") { SUBCASE("copy ctor") {
@@ -258,77 +258,77 @@ TEST_CASE("meta/meta_utilities/value2/counters/big") {
CHECK(v1.cast<ivec2_big>().x == 1); CHECK(v1.cast<ivec2_big>().x == 1);
CHECK(v2.cast<ivec2_big>().y == 2); CHECK(v2.cast<ivec2_big>().y == 2);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 1); CHECK(ivec2_big::copy_constructor_counter == 1);
} }
CHECK(ivec2_big::dtor_counter == 3); CHECK(ivec2_big::destructor_counter == 3);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 1); CHECK(ivec2_big::copy_constructor_counter == 1);
} }
SUBCASE("swap") { SUBCASE("swap") {
{ {
meta::uvalue v1{ivec2_big{1,2}}; meta::uvalue v1{ivec2_big{1,2}};
meta::uvalue v2{ivec2_big{3,4}}; meta::uvalue v2{ivec2_big{3,4}};
CHECK(ivec2_big::dtor_counter == 2); CHECK(ivec2_big::destructor_counter == 2);
CHECK(ivec2_big::move_ctor_counter == 2); CHECK(ivec2_big::move_constructor_counter == 2);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK(v1.cast<ivec2_big>().x == 3); CHECK(v1.cast<ivec2_big>().x == 3);
CHECK(v2.cast<ivec2_big>().x == 1); CHECK(v2.cast<ivec2_big>().x == 1);
CHECK(ivec2_big::dtor_counter == 2); CHECK(ivec2_big::destructor_counter == 2);
CHECK(ivec2_big::move_ctor_counter == 2); CHECK(ivec2_big::move_constructor_counter == 2);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
CHECK(ivec2_big::dtor_counter == 4); CHECK(ivec2_big::destructor_counter == 4);
CHECK(ivec2_big::move_ctor_counter == 2); CHECK(ivec2_big::move_constructor_counter == 2);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
} }
TEST_CASE("meta/meta_utilities/value2/counters/swap") { TEST_CASE("meta/meta_utilities/value2/counters/swap") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
ivec2::dtor_counter = 0; ivec2::destructor_counter = 0;
ivec2::move_ctor_counter = 0; ivec2::move_constructor_counter = 0;
ivec2::copy_ctor_counter = 0; ivec2::copy_constructor_counter = 0;
ivec2_big::dtor_counter = 0; ivec2_big::destructor_counter = 0;
ivec2_big::move_ctor_counter = 0; ivec2_big::move_constructor_counter = 0;
ivec2_big::copy_ctor_counter = 0; ivec2_big::copy_constructor_counter = 0;
SUBCASE("empty/small") { SUBCASE("empty/small") {
{ {
meta::uvalue v1{}; meta::uvalue v1{};
meta::uvalue v2{ivec2{1,2}}; meta::uvalue v2{ivec2{1,2}};
CHECK(ivec2::dtor_counter == 1); CHECK(ivec2::destructor_counter == 1);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK(v1.cast<ivec2>().x == 1); CHECK(v1.cast<ivec2>().x == 1);
CHECK_FALSE(v2); CHECK_FALSE(v2);
CHECK(ivec2::dtor_counter == 2); CHECK(ivec2::destructor_counter == 2);
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK_FALSE(v1); CHECK_FALSE(v1);
CHECK(v2.cast<ivec2>().y == 2); CHECK(v2.cast<ivec2>().y == 2);
CHECK(ivec2::dtor_counter == 3); CHECK(ivec2::destructor_counter == 3);
CHECK(ivec2::move_ctor_counter == 3); CHECK(ivec2::move_constructor_counter == 3);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
CHECK(ivec2::dtor_counter == 4); CHECK(ivec2::destructor_counter == 4);
CHECK(ivec2::move_ctor_counter == 3); CHECK(ivec2::move_constructor_counter == 3);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
SUBCASE("empty/big") { SUBCASE("empty/big") {
@@ -336,30 +336,30 @@ TEST_CASE("meta/meta_utilities/value2/counters/swap") {
meta::uvalue v1{}; meta::uvalue v1{};
meta::uvalue v2{ivec2_big{3,4}}; meta::uvalue v2{ivec2_big{3,4}};
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK(v1.cast<ivec2_big>().x == 3); CHECK(v1.cast<ivec2_big>().x == 3);
CHECK_FALSE(v2); CHECK_FALSE(v2);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK_FALSE(v1); CHECK_FALSE(v1);
CHECK(v2.cast<ivec2_big>().y == 4); CHECK(v2.cast<ivec2_big>().y == 4);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
CHECK(ivec2_big::dtor_counter == 2); CHECK(ivec2_big::destructor_counter == 2);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
SUBCASE("small/big") { SUBCASE("small/big") {
@@ -367,45 +367,45 @@ TEST_CASE("meta/meta_utilities/value2/counters/swap") {
meta::uvalue v1{ivec2{1,2}}; meta::uvalue v1{ivec2{1,2}};
meta::uvalue v2{ivec2_big{3,4}}; meta::uvalue v2{ivec2_big{3,4}};
CHECK(ivec2::dtor_counter == 1); CHECK(ivec2::destructor_counter == 1);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK(v1.cast<ivec2_big>().x == 3); CHECK(v1.cast<ivec2_big>().x == 3);
CHECK(v2.cast<ivec2>().x == 1); CHECK(v2.cast<ivec2>().x == 1);
CHECK(ivec2::dtor_counter == 2); CHECK(ivec2::destructor_counter == 2);
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
v1.swap(v2); v1.swap(v2);
CHECK(v1.cast<ivec2>().y == 2); CHECK(v1.cast<ivec2>().y == 2);
CHECK(v2.cast<ivec2_big>().y == 4); CHECK(v2.cast<ivec2_big>().y == 4);
CHECK(ivec2::dtor_counter == 3); CHECK(ivec2::destructor_counter == 3);
CHECK(ivec2::move_ctor_counter == 3); CHECK(ivec2::move_constructor_counter == 3);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
CHECK(ivec2_big::dtor_counter == 1); CHECK(ivec2_big::destructor_counter == 1);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
CHECK(ivec2::dtor_counter == 4); CHECK(ivec2::destructor_counter == 4);
CHECK(ivec2::move_ctor_counter == 3); CHECK(ivec2::move_constructor_counter == 3);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
CHECK(ivec2_big::dtor_counter == 2); CHECK(ivec2_big::destructor_counter == 2);
CHECK(ivec2_big::move_ctor_counter == 1); CHECK(ivec2_big::move_constructor_counter == 1);
CHECK(ivec2_big::copy_ctor_counter == 0); CHECK(ivec2_big::copy_constructor_counter == 0);
} }
} }

View File

@@ -21,13 +21,13 @@ namespace
, y{other.y} { , y{other.y} {
other.x = 0; other.x = 0;
other.y = 0; other.y = 0;
++move_ctor_counter; ++move_constructor_counter;
} }
ivec2(const ivec2& other) noexcept ivec2(const ivec2& other) noexcept
: x{other.x} : x{other.x}
, y{other.y} { , y{other.y} {
++copy_ctor_counter; ++copy_constructor_counter;
} }
ivec2& add(const ivec2& other) { ivec2& add(const ivec2& other) {
@@ -39,8 +39,8 @@ namespace
ivec2& operator=(ivec2&& other) = delete; ivec2& operator=(ivec2&& other) = delete;
ivec2& operator=(const ivec2& other) = delete; ivec2& operator=(const ivec2& other) = delete;
public: public:
static int move_ctor_counter; static int move_constructor_counter;
static int copy_ctor_counter; static int copy_constructor_counter;
}; };
struct ivec3 { struct ivec3 {
@@ -53,8 +53,8 @@ namespace
ivec3(int x, int y, int z): x{x}, y{y}, z{z} {} ivec3(int x, int y, int z): x{x}, y{y}, z{z} {}
}; };
int ivec2::move_ctor_counter{0}; int ivec2::move_constructor_counter{0};
int ivec2::copy_ctor_counter{0}; int ivec2::copy_constructor_counter{0};
ivec2 iadd2(ivec2 l, ivec2 r) { ivec2 iadd2(ivec2 l, ivec2 r) {
return {l.x + r.x, l.y + r.y}; return {l.x + r.x, l.y + r.y};
@@ -73,10 +73,10 @@ TEST_CASE("meta/meta_utilities/value/ivec2") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
meta::class_<ivec2>() meta::class_<ivec2>()
.ctor_<int>() .constructor_<int>()
.ctor_<int, int>() .constructor_<int, int>()
.ctor_<ivec2&&>() .constructor_<ivec2&&>()
.ctor_<const ivec2&>() .constructor_<const ivec2&>()
.member_("x", &ivec2::x) .member_("x", &ivec2::x)
.member_("y", &ivec2::y); .member_("y", &ivec2::y);
} }
@@ -85,10 +85,10 @@ TEST_CASE("meta/meta_utilities/value/ivec3") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
meta::class_<ivec3>() meta::class_<ivec3>()
.ctor_<int>() .constructor_<int>()
.ctor_<int, int, int>() .constructor_<int, int, int>()
.ctor_<ivec3&&>() .constructor_<ivec3&&>()
.ctor_<const ivec3&>() .constructor_<const ivec3&>()
.member_("x", &ivec3::x) .member_("x", &ivec3::x)
.member_("y", &ivec3::y) .member_("y", &ivec3::y)
.member_("z", &ivec3::z); .member_("z", &ivec3::z);
@@ -98,8 +98,8 @@ TEST_CASE("meta/meta_utilities/value") {
namespace meta = meta_hpp; namespace meta = meta_hpp;
using namespace std::string_literals; using namespace std::string_literals;
ivec2::move_ctor_counter = 0; ivec2::move_constructor_counter = 0;
ivec2::copy_ctor_counter = 0; ivec2::copy_constructor_counter = 0;
SUBCASE("cast types") { SUBCASE("cast types") {
static_assert(std::is_same_v< static_assert(std::is_same_v<
@@ -189,8 +189,8 @@ TEST_CASE("meta/meta_utilities/value") {
ivec2& vr = v; ivec2& vr = v;
meta::uvalue val{vr}; meta::uvalue val{vr};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
CHECK(val.get_type() == meta::resolve_type<ivec2>()); CHECK(val.get_type() == meta::resolve_type<ivec2>());
@@ -223,8 +223,8 @@ TEST_CASE("meta/meta_utilities/value") {
const ivec2& vr = v; const ivec2& vr = v;
meta::uvalue val{vr}; meta::uvalue val{vr};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
CHECK(val.get_type() == meta::resolve_type<ivec2>()); CHECK(val.get_type() == meta::resolve_type<ivec2>());
@@ -256,8 +256,8 @@ TEST_CASE("meta/meta_utilities/value") {
ivec2 v{1,2}; ivec2 v{1,2};
meta::uvalue val{std::move(v)}; meta::uvalue val{std::move(v)};
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
CHECK(val.get_type() == meta::resolve_type<ivec2>()); CHECK(val.get_type() == meta::resolve_type<ivec2>());
@@ -284,8 +284,8 @@ TEST_CASE("meta/meta_utilities/value") {
const ivec2 v{1,2}; const ivec2 v{1,2};
meta::uvalue val{std::move(v)}; meta::uvalue val{std::move(v)};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
CHECK(val.get_type() == meta::resolve_type<ivec2>()); CHECK(val.get_type() == meta::resolve_type<ivec2>());
@@ -311,25 +311,25 @@ TEST_CASE("meta/meta_utilities/value") {
SUBCASE("value(value&&)") { SUBCASE("value(value&&)") {
ivec2 v{1,2}; ivec2 v{1,2};
meta::uvalue val_src{std::move(v)}; meta::uvalue val_src{std::move(v)};
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
meta::uvalue val_dst{std::move(val_src)}; meta::uvalue val_dst{std::move(val_src)};
CHECK(val_dst == ivec2{1,2}); CHECK(val_dst == ivec2{1,2});
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
SUBCASE("value(const meta::value&)") { SUBCASE("value(const meta::value&)") {
const ivec2 v{1,2}; const ivec2 v{1,2};
meta::uvalue val_src{v}; meta::uvalue val_src{v};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
meta::uvalue val_dst{val_src}; meta::uvalue val_dst{val_src};
CHECK(val_dst == ivec2{1,2}); CHECK(val_dst == ivec2{1,2});
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 2); CHECK(ivec2::copy_constructor_counter == 2);
CHECK(val_src == ivec2{1,2}); CHECK(val_src == ivec2{1,2});
CHECK(val_src.data() != val_dst.data()); CHECK(val_src.data() != val_dst.data());
@@ -348,39 +348,39 @@ TEST_CASE("meta/meta_utilities/value") {
SUBCASE("value& operator=(value&&)") { SUBCASE("value& operator=(value&&)") {
meta::uvalue val_src1{"world"s}; meta::uvalue val_src1{"world"s};
meta::uvalue val_src2{ivec2{1,2}}; meta::uvalue val_src2{ivec2{1,2}};
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
meta::uvalue val_dst{"hello"s}; meta::uvalue val_dst{"hello"s};
val_dst = std::move(val_src1); val_dst = std::move(val_src1);
CHECK(val_dst == "world"s); CHECK(val_dst == "world"s);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
val_dst = std::move(val_src2); val_dst = std::move(val_src2);
CHECK(val_dst == ivec2{1,2}); CHECK(val_dst == ivec2{1,2});
CHECK(ivec2::move_ctor_counter == 3); CHECK(ivec2::move_constructor_counter == 3);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
} }
SUBCASE("value& operator=(const meta::value&)") { SUBCASE("value& operator=(const meta::value&)") {
meta::uvalue val_src1{"world"s}; meta::uvalue val_src1{"world"s};
meta::uvalue val_src2{ivec2{1,2}}; meta::uvalue val_src2{ivec2{1,2}};
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
meta::uvalue val_dst{"hello"s}; meta::uvalue val_dst{"hello"s};
val_dst = val_src1; val_dst = val_src1;
CHECK(val_dst == "world"s); CHECK(val_dst == "world"s);
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
val_dst = val_src2; val_dst = val_src2;
CHECK(val_dst == ivec2{1,2}); CHECK(val_dst == ivec2{1,2});
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
CHECK(val_src2 == ivec2{1,2}); CHECK(val_src2 == ivec2{1,2});
CHECK(val_src2.data() != val_dst.data()); CHECK(val_src2.data() != val_dst.data());
@@ -389,14 +389,14 @@ TEST_CASE("meta/meta_utilities/value") {
SUBCASE("swap") { SUBCASE("swap") {
meta::uvalue val1{"world"s}; meta::uvalue val1{"world"s};
meta::uvalue val2{ivec2{1,2}}; meta::uvalue val2{ivec2{1,2}};
CHECK(ivec2::move_ctor_counter == 1); CHECK(ivec2::move_constructor_counter == 1);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
val1.swap(val2); val1.swap(val2);
CHECK(val1 == ivec2{1,2}); CHECK(val1 == ivec2{1,2});
CHECK(val2 == "world"s); CHECK(val2 == "world"s);
CHECK(ivec2::move_ctor_counter == 2); CHECK(ivec2::move_constructor_counter == 2);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
swap(val1, val2); swap(val1, val2);
CHECK(val1 == "world"s); CHECK(val1 == "world"s);
@@ -498,20 +498,20 @@ TEST_CASE("meta/meta_utilities/value") {
{ {
ivec2 v{1,2}; ivec2 v{1,2};
meta::uvalue vp{&v}; meta::uvalue vp{&v};
CHECK(ivec2::move_ctor_counter == 0); CHECK(ivec2::move_constructor_counter == 0);
CHECK(ivec2::copy_ctor_counter == 0); CHECK(ivec2::copy_constructor_counter == 0);
[[maybe_unused]] meta::uvalue vv1{*vp}; [[maybe_unused]] meta::uvalue vv1{*vp};
CHECK((ivec2::move_ctor_counter == 0 || ivec2::move_ctor_counter == 2)); CHECK((ivec2::move_constructor_counter == 0 || ivec2::move_constructor_counter == 2));
CHECK(ivec2::copy_ctor_counter == 1); CHECK(ivec2::copy_constructor_counter == 1);
[[maybe_unused]] meta::uvalue vv2{*std::move(vp)}; [[maybe_unused]] meta::uvalue vv2{*std::move(vp)};
CHECK((ivec2::move_ctor_counter == 0 || ivec2::move_ctor_counter == 4)); CHECK((ivec2::move_constructor_counter == 0 || ivec2::move_constructor_counter == 4));
CHECK(ivec2::copy_ctor_counter == 2); CHECK(ivec2::copy_constructor_counter == 2);
[[maybe_unused]] meta::uvalue vv3{*std::as_const(vp)}; [[maybe_unused]] meta::uvalue vv3{*std::as_const(vp)};
CHECK((ivec2::move_ctor_counter == 0 || ivec2::move_ctor_counter == 6)); CHECK((ivec2::move_constructor_counter == 0 || ivec2::move_constructor_counter == 6));
CHECK(ivec2::copy_ctor_counter == 3); CHECK(ivec2::copy_constructor_counter == 3);
} }
{ {
meta::uvalue v{std::make_shared<int>(42)}; meta::uvalue v{std::make_shared<int>(42)};