overridable assert macro

This commit is contained in:
BlackMATov
2023-02-09 00:08:52 +07:00
parent c452ff532a
commit 176813304e
4 changed files with 45 additions and 30 deletions

View File

@@ -14,7 +14,6 @@
# define META_HPP_NO_RTTI
#endif
#include <cassert>
#include <climits>
#include <cstddef>
#include <cstdint>
@@ -49,3 +48,8 @@
# include <typeindex>
# include <typeinfo>
#endif
#if !defined(META_HPP_ASSERT)
# include <cassert>
# define META_HPP_ASSERT(...) assert(__VA_ARGS__) // NOLINT
#endif

View File

@@ -7,6 +7,7 @@
#pragma once
#include "base.hpp"
#include "exceptions.hpp"
namespace meta_hpp::detail
{
@@ -63,7 +64,7 @@ namespace meta_hpp::detail
}
R operator()(Args... args) const {
assert(vtable_ && "bad function call"); // NOLINT
META_HPP_ASSERT(vtable_ && "bad function call");
return vtable_->call(*this, std::forward<Args>(args)...);
}
@@ -120,14 +121,15 @@ namespace meta_hpp::detail
static vtable_t table{
.call{[](const fixed_function& self, Args... args) -> R {
assert(self); // NOLINT
META_HPP_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 {
assert(from && !to); // NOLINT
META_HPP_ASSERT(!to);
META_HPP_ASSERT(from);
Fp& src = *buffer_cast<Fp>(from.buffer_);
std::construct_at(buffer_cast<Fp>(to.buffer_), std::move(src));
@@ -138,7 +140,7 @@ namespace meta_hpp::detail
}},
.destroy{[](fixed_function& self) {
assert(self); // NOLINT
META_HPP_ASSERT(self);
Fp& src = *buffer_cast<Fp>(self.buffer_);
std::destroy_at(&src);
@@ -151,7 +153,7 @@ namespace meta_hpp::detail
template < typename F, typename Fp = std::decay_t<F> >
static void construct(fixed_function& dst, F&& fun) {
assert(!dst); // NOLINT
META_HPP_ASSERT(!dst);
static_assert(sizeof(Fp) <= sizeof(buffer_t));
static_assert(alignof(buffer_t) % alignof(Fp) == 0);

View File

@@ -72,7 +72,7 @@ namespace meta_hpp
template < typename T, typename... Args, typename Tp = std::decay_t<T> >
static Tp& do_ctor(uvalue& dst, Args&&... args) {
assert(!dst); // NOLINT
META_HPP_ASSERT(!dst);
if constexpr ( in_internal_v<Tp> ) {
std::construct_at(storage_cast<Tp>(dst.storage_), std::forward<Args>(args)...);
@@ -90,7 +90,7 @@ namespace meta_hpp
}
static void do_move(uvalue&& self, uvalue& to) noexcept {
assert(!to); // NOLINT
META_HPP_ASSERT(!to);
auto&& [tag, vtable] = unpack_vtag(self);
@@ -109,7 +109,7 @@ namespace meta_hpp
}
static void do_copy(const uvalue& self, uvalue& to) noexcept {
assert(!to); // NOLINT
META_HPP_ASSERT(!to);
auto&& [tag, vtable] = unpack_vtag(self);
@@ -171,7 +171,8 @@ namespace meta_hpp
.type = resolve_type<Tp>(),
.move{[](uvalue&& self, uvalue& to) noexcept {
assert(self && !to); // NOLINT
META_HPP_ASSERT(!to);
META_HPP_ASSERT(self);
Tp* src = storage_cast<Tp>(self.storage_);
@@ -186,7 +187,8 @@ namespace meta_hpp
}},
.copy{[](const uvalue& self, uvalue& to) {
assert(self && !to); // NOLINT
META_HPP_ASSERT(!to);
META_HPP_ASSERT(self);
const Tp* src = storage_cast<Tp>(self.storage_);
@@ -200,7 +202,7 @@ namespace meta_hpp
}},
.reset{[](uvalue& self) noexcept {
assert(self); // NOLINT
META_HPP_ASSERT(self);
Tp* src = storage_cast<Tp>(self.storage_);
@@ -363,7 +365,7 @@ namespace meta_hpp
return storage_.external.ptr;
}
assert(false); // NOLINT
META_HPP_ASSERT(false);
return nullptr;
}
@@ -380,7 +382,7 @@ namespace meta_hpp
return storage_.external.ptr;
}
assert(false); // NOLINT
META_HPP_ASSERT(false);
return nullptr;
}
@@ -397,7 +399,7 @@ namespace meta_hpp
return storage_.external.ptr;
}
assert(false); // NOLINT
META_HPP_ASSERT(false);
return nullptr;
}