mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
add dev assets
This commit is contained in:
@@ -53,6 +53,12 @@
|
||||
# define META_HPP_ASSERT(...) assert(__VA_ARGS__) // NOLINT
|
||||
#endif
|
||||
|
||||
#if defined(META_HPP_SANITIZERS)
|
||||
# define META_HPP_DEV_ASSERT(...) META_HPP_ASSERT(__VA_ARGS__)
|
||||
#else
|
||||
# define META_HPP_DEV_ASSERT(...) (void)0
|
||||
#endif
|
||||
|
||||
#if !defined(META_HPP_PP_CAT)
|
||||
# define META_HPP_PP_CAT(x, y) META_HPP_PP_CAT_I(x, y)
|
||||
# define META_HPP_PP_CAT_I(x, y) x##y
|
||||
|
||||
@@ -126,15 +126,15 @@ namespace meta_hpp::detail
|
||||
|
||||
static vtable_t table{
|
||||
.call{[](const fixed_function& self, Args... args) -> R {
|
||||
META_HPP_ASSERT(self);
|
||||
META_HPP_DEV_ASSERT(self);
|
||||
|
||||
const Fp& src = *buffer_cast<Fp>(self.buffer_);
|
||||
return std::invoke(src, std::forward<Args>(args)...);
|
||||
}},
|
||||
|
||||
.move{[](fixed_function& from, fixed_function& to) noexcept {
|
||||
META_HPP_ASSERT(!to);
|
||||
META_HPP_ASSERT(from);
|
||||
META_HPP_DEV_ASSERT(!to);
|
||||
META_HPP_DEV_ASSERT(from);
|
||||
|
||||
Fp& src = *buffer_cast<Fp>(from.buffer_);
|
||||
std::construct_at(buffer_cast<Fp>(to.buffer_), std::move(src));
|
||||
@@ -145,7 +145,7 @@ namespace meta_hpp::detail
|
||||
}},
|
||||
|
||||
.destroy{[](fixed_function& self) {
|
||||
META_HPP_ASSERT(self);
|
||||
META_HPP_DEV_ASSERT(self);
|
||||
|
||||
Fp& src = *buffer_cast<Fp>(self.buffer_);
|
||||
std::destroy_at(&src);
|
||||
@@ -158,7 +158,7 @@ namespace meta_hpp::detail
|
||||
|
||||
template < typename F, typename Fp = std::decay_t<F> >
|
||||
static void construct(fixed_function& dst, F&& fun) {
|
||||
META_HPP_ASSERT(!dst);
|
||||
META_HPP_DEV_ASSERT(!dst);
|
||||
|
||||
static_assert(sizeof(Fp) <= sizeof(buffer_t));
|
||||
static_assert(alignof(buffer_t) % alignof(Fp) == 0);
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < pointer_kind To >
|
||||
[[nodiscard]] decltype(auto) uarg::cast(type_registry& registry) const {
|
||||
META_HPP_ASSERT(can_cast_to<To>(registry) && "bad argument cast");
|
||||
META_HPP_DEV_ASSERT(can_cast_to<To>(registry) && "bad argument cast");
|
||||
|
||||
using to_raw_type = std::remove_cv_t<To>;
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace meta_hpp::detail
|
||||
|
||||
template < non_pointer_kind To >
|
||||
[[nodiscard]] decltype(auto) uarg::cast(type_registry& registry) const {
|
||||
META_HPP_ASSERT(can_cast_to<To>(registry) && "bad argument cast");
|
||||
META_HPP_DEV_ASSERT(can_cast_to<To>(registry) && "bad argument cast");
|
||||
|
||||
using to_raw_type_cv = std::remove_reference_t<To>;
|
||||
using to_raw_type = std::remove_cv_t<to_raw_type_cv>;
|
||||
@@ -333,18 +333,11 @@ namespace meta_hpp::detail
|
||||
|
||||
namespace meta_hpp::detail
|
||||
{
|
||||
template < typename ArgTypeList, typename F >
|
||||
auto call_with_uargs(type_registry& registry, std::span<const uarg> args, F&& f) {
|
||||
META_HPP_ASSERT(args.size() == type_list_arity_v<ArgTypeList>);
|
||||
return [ args, ®istry, &f ]<std::size_t... Is>(std::index_sequence<Is...>) {
|
||||
return f(args[Is].cast<type_list_at_t<Is, ArgTypeList>>(registry)...);
|
||||
}
|
||||
(std::make_index_sequence<type_list_arity_v<ArgTypeList>>());
|
||||
}
|
||||
|
||||
template < typename ArgTypeList >
|
||||
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg> args) {
|
||||
META_HPP_ASSERT(args.size() == type_list_arity_v<ArgTypeList>);
|
||||
if ( args.size() != type_list_arity_v<ArgTypeList> ) {
|
||||
return false;
|
||||
}
|
||||
return [ args, ®istry ]<std::size_t... Is>(std::index_sequence<Is...>) {
|
||||
return (... && args[Is].can_cast_to<type_list_at_t<Is, ArgTypeList>>(registry));
|
||||
}
|
||||
@@ -353,10 +346,21 @@ namespace meta_hpp::detail
|
||||
|
||||
template < typename ArgTypeList >
|
||||
bool can_cast_all_uargs(type_registry& registry, std::span<const uarg_base> args) {
|
||||
META_HPP_ASSERT(args.size() == type_list_arity_v<ArgTypeList>);
|
||||
if ( args.size() != type_list_arity_v<ArgTypeList> ) {
|
||||
return false;
|
||||
}
|
||||
return [ args, ®istry ]<std::size_t... Is>(std::index_sequence<Is...>) {
|
||||
return (... && args[Is].can_cast_to<type_list_at_t<Is, ArgTypeList>>(registry));
|
||||
}
|
||||
(std::make_index_sequence<type_list_arity_v<ArgTypeList>>());
|
||||
}
|
||||
|
||||
template < typename ArgTypeList, typename F >
|
||||
auto unchecked_call_with_uargs(type_registry& registry, std::span<const uarg> args, F&& f) {
|
||||
META_HPP_DEV_ASSERT(args.size() == type_list_arity_v<ArgTypeList>);
|
||||
return [ args, ®istry, &f ]<std::size_t... Is>(std::index_sequence<Is...>) {
|
||||
return f(args[Is].cast<type_list_at_t<Is, ArgTypeList>>(registry)...);
|
||||
}
|
||||
(std::make_index_sequence<type_list_arity_v<ArgTypeList>>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace meta_hpp::detail
|
||||
{
|
||||
template < inst_class_ref_kind Q >
|
||||
decltype(auto) uinst::cast(type_registry& registry) const {
|
||||
META_HPP_ASSERT(can_cast_to<Q>(registry) && "bad instance cast");
|
||||
META_HPP_DEV_ASSERT(can_cast_to<Q>(registry) && "bad instance cast");
|
||||
|
||||
using inst_class_cv = std::remove_reference_t<Q>;
|
||||
using inst_class = std::remove_cv_t<inst_class_cv>;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace meta_hpp::detail
|
||||
&& "an attempt to call a constructor with incorrect argument types"
|
||||
);
|
||||
|
||||
return call_with_uargs<argument_types>(registry, args, [](auto&&... all_args) -> uvalue {
|
||||
return unchecked_call_with_uargs<argument_types>(registry, args, [](auto&&... all_args) -> uvalue {
|
||||
if constexpr ( as_object ) {
|
||||
return make_uvalue<class_type>(META_HPP_FWD(all_args)...);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace meta_hpp::detail
|
||||
&& "an attempt to call a constructor with incorrect argument types"
|
||||
);
|
||||
|
||||
return call_with_uargs<argument_types>(registry, args, [mem](auto&&... all_args) {
|
||||
return unchecked_call_with_uargs<argument_types>(registry, args, [mem](auto&&... all_args) {
|
||||
return std::construct_at(static_cast<class_type*>(mem), META_HPP_FWD(all_args)...);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace meta_hpp::detail
|
||||
&& "an attempt to call a function with incorrect argument types"
|
||||
);
|
||||
|
||||
return call_with_uargs<argument_types>(registry, args, [function_ptr](auto&&... all_args) {
|
||||
return unchecked_call_with_uargs<argument_types>(registry, args, [function_ptr](auto&&... all_args) {
|
||||
if constexpr ( std::is_void_v<return_type> ) {
|
||||
function_ptr(META_HPP_FWD(all_args)...);
|
||||
return uvalue{};
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace meta_hpp::detail
|
||||
&& "an attempt to call a method with incorrect argument types"
|
||||
);
|
||||
|
||||
return call_with_uargs<argument_types>(registry, args, [method_ptr, &inst, ®istry](auto&&... all_args) {
|
||||
return unchecked_call_with_uargs<argument_types>(registry, args, [method_ptr, &inst, ®istry](auto&&... all_args) {
|
||||
if constexpr ( std::is_void_v<return_type> ) {
|
||||
(inst.cast<qualified_type>(registry).*method_ptr)(META_HPP_FWD(all_args)...);
|
||||
return uvalue{};
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace meta_hpp
|
||||
|
||||
template < typename T, typename... Args, typename Tp = std::decay_t<T> >
|
||||
static Tp& do_ctor(uvalue& dst, Args&&... args) {
|
||||
META_HPP_ASSERT(!dst);
|
||||
META_HPP_DEV_ASSERT(!dst);
|
||||
|
||||
if constexpr ( in_internal_v<Tp> ) {
|
||||
std::construct_at(storage_cast<Tp>(dst.storage_), std::forward<Args>(args)...);
|
||||
@@ -91,7 +91,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
static void do_move(uvalue&& self, uvalue& to) noexcept {
|
||||
META_HPP_ASSERT(!to);
|
||||
META_HPP_DEV_ASSERT(!to);
|
||||
|
||||
auto&& [tag, vtable] = unpack_vtag(self);
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
static void do_copy(const uvalue& self, uvalue& to) noexcept {
|
||||
META_HPP_ASSERT(!to);
|
||||
META_HPP_DEV_ASSERT(!to);
|
||||
|
||||
auto&& [tag, vtable] = unpack_vtag(self);
|
||||
|
||||
@@ -172,8 +172,8 @@ namespace meta_hpp
|
||||
.type = resolve_type<Tp>(),
|
||||
|
||||
.move{[](uvalue&& self, uvalue& to) noexcept {
|
||||
META_HPP_ASSERT(!to);
|
||||
META_HPP_ASSERT(self);
|
||||
META_HPP_DEV_ASSERT(!to);
|
||||
META_HPP_DEV_ASSERT(self);
|
||||
|
||||
Tp* src = storage_cast<Tp>(self.storage_);
|
||||
|
||||
@@ -188,8 +188,8 @@ namespace meta_hpp
|
||||
}},
|
||||
|
||||
.copy{[](const uvalue& self, uvalue& to) {
|
||||
META_HPP_ASSERT(!to);
|
||||
META_HPP_ASSERT(self);
|
||||
META_HPP_DEV_ASSERT(!to);
|
||||
META_HPP_DEV_ASSERT(self);
|
||||
|
||||
const Tp* src = storage_cast<Tp>(self.storage_);
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace meta_hpp
|
||||
}},
|
||||
|
||||
.reset{[](uvalue& self) noexcept {
|
||||
META_HPP_ASSERT(self);
|
||||
META_HPP_DEV_ASSERT(self);
|
||||
|
||||
Tp* src = storage_cast<Tp>(self.storage_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user