mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 19:18:01 +07:00
return is_valid instead is_empty
This commit is contained in:
@@ -441,12 +441,12 @@ namespace meta_hpp::detail
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_empty() const noexcept {
|
||||
return vtable_ == nullptr;
|
||||
[[nodiscard]] bool is_valid() const noexcept {
|
||||
return vtable_ != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] explicit operator bool() const noexcept {
|
||||
return vtable_ != nullptr;
|
||||
return is_valid();
|
||||
}
|
||||
|
||||
R operator()(Args... args) const {
|
||||
@@ -1088,12 +1088,12 @@ namespace meta_hpp::detail
|
||||
reset();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool is_empty() const noexcept {
|
||||
return data_ == nullptr;
|
||||
[[nodiscard]] bool is_valid() const noexcept {
|
||||
return data_ != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] explicit operator bool() const noexcept {
|
||||
return data_ != nullptr;
|
||||
return is_valid();
|
||||
}
|
||||
|
||||
void reset() noexcept {
|
||||
@@ -2235,12 +2235,12 @@ namespace meta_hpp
|
||||
type_base& operator=(type_base&&) noexcept = default;
|
||||
type_base& operator=(const type_base&) = default;
|
||||
|
||||
[[nodiscard]] bool is_empty() const noexcept {
|
||||
return data_ == nullptr;
|
||||
[[nodiscard]] bool is_valid() const noexcept {
|
||||
return data_ != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] explicit operator bool() const noexcept {
|
||||
return data_ != nullptr;
|
||||
return is_valid();
|
||||
}
|
||||
|
||||
[[nodiscard]] type_id get_id() const noexcept {
|
||||
@@ -2497,7 +2497,7 @@ namespace std
|
||||
template < meta_hpp::detail::type_family Type >
|
||||
struct hash<Type> {
|
||||
size_t operator()(const Type& type) const noexcept {
|
||||
return type.is_empty() ? 0 : type.get_id().get_hash();
|
||||
return type.is_valid() ? type.get_id().get_hash() : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2506,15 +2506,15 @@ namespace meta_hpp
|
||||
{
|
||||
template < detail::type_family L, detail::type_family R >
|
||||
[[nodiscard]] bool operator==(const L& l, const R& r) noexcept {
|
||||
return l.is_empty() == r.is_empty() && (l.is_empty() || l.get_id() == r.get_id());
|
||||
return l.is_valid() == r.is_valid() && (!l.is_valid() || l.get_id() == r.get_id());
|
||||
}
|
||||
|
||||
template < detail::type_family L, detail::type_family R >
|
||||
[[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept {
|
||||
if ( const std::strong_ordering cmp{!l.is_empty() <=> !r.is_empty()}; cmp != std::strong_ordering::equal ) {
|
||||
if ( const std::strong_ordering cmp{l.is_valid() <=> r.is_valid()}; cmp != std::strong_ordering::equal ) {
|
||||
return cmp;
|
||||
}
|
||||
return l.is_empty() ? std::strong_ordering::equal : l.get_id() <=> r.get_id();
|
||||
return l.is_valid() ? l.get_id() <=> r.get_id() : std::strong_ordering::equal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2522,12 +2522,12 @@ namespace meta_hpp
|
||||
{
|
||||
template < detail::type_family L >
|
||||
[[nodiscard]] bool operator==(const L& l, type_id r) noexcept {
|
||||
return !l.is_empty() && l.get_id() == r;
|
||||
return l.is_valid() && l.get_id() == r;
|
||||
}
|
||||
|
||||
template < detail::type_family L >
|
||||
[[nodiscard]] std::strong_ordering operator<=>(const L& l, type_id r) noexcept {
|
||||
return !l.is_empty() ? l.get_id() <=> r : std::strong_ordering::less;
|
||||
return l.is_valid() ? l.get_id() <=> r : std::strong_ordering::less;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3366,12 +3366,12 @@ namespace meta_hpp
|
||||
state_base& operator=(state_base&&) noexcept = default;
|
||||
state_base& operator=(const state_base&) = default;
|
||||
|
||||
[[nodiscard]] bool is_empty() const noexcept {
|
||||
return state_ == nullptr;
|
||||
[[nodiscard]] bool is_valid() const noexcept {
|
||||
return state_ != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] explicit operator bool() const noexcept {
|
||||
return state_ != nullptr;
|
||||
return is_valid();
|
||||
}
|
||||
|
||||
[[nodiscard]] const index_type& get_index() const noexcept {
|
||||
@@ -3632,7 +3632,7 @@ namespace std
|
||||
template < meta_hpp::detail::state_family State >
|
||||
struct hash<State> {
|
||||
size_t operator()(const State& state) const noexcept {
|
||||
return state.is_empty() ? 0 : state.get_index().get_hash();
|
||||
return state.is_valid() ? state.get_index().get_hash() : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -3641,15 +3641,15 @@ namespace meta_hpp
|
||||
{
|
||||
template < detail::state_family L, detail::state_family R >
|
||||
[[nodiscard]] bool operator==(const L& l, const R& r) noexcept {
|
||||
return l.is_empty() == r.is_empty() && (l.is_empty() || l.get_index() == r.get_index());
|
||||
return l.is_valid() == r.is_valid() && (!l.is_valid() || l.get_index() == r.get_index());
|
||||
}
|
||||
|
||||
template < detail::state_family L, detail::state_family R >
|
||||
[[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept {
|
||||
if ( const std::strong_ordering cmp{!l.is_empty() <=> !r.is_empty()}; cmp != std::strong_ordering::equal ) {
|
||||
if ( const std::strong_ordering cmp{l.is_valid() <=> r.is_valid()}; cmp != std::strong_ordering::equal ) {
|
||||
return cmp;
|
||||
}
|
||||
return l.is_empty() ? std::strong_ordering::equal : l.get_index() <=> r.get_index();
|
||||
return l.is_valid() ? l.get_index() <=> r.get_index() : std::strong_ordering::equal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3657,12 +3657,12 @@ namespace meta_hpp
|
||||
{
|
||||
template < detail::state_family L, detail::index_family R >
|
||||
[[nodiscard]] bool operator==(const L& l, const R& r) noexcept {
|
||||
return !l.is_empty() && l.get_index() == r;
|
||||
return l.is_valid() && l.get_index() == r;
|
||||
}
|
||||
|
||||
template < detail::state_family L, detail::index_family R >
|
||||
[[nodiscard]] std::strong_ordering operator<=>(const L& l, const R& r) noexcept {
|
||||
return !l.is_empty() ? l.get_index() <=> r : std::strong_ordering::less;
|
||||
return l.is_valid() ? l.get_index() <=> r : std::strong_ordering::less;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7873,7 +7873,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
inline bool class_type::is_base_of(const class_type& derived) const noexcept {
|
||||
if ( is_empty() || derived.is_empty() ) {
|
||||
if ( !is_valid() || !derived.is_valid() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7897,7 +7897,7 @@ namespace meta_hpp
|
||||
}
|
||||
|
||||
inline bool class_type::is_derived_from(const class_type& base) const noexcept {
|
||||
if ( is_empty() || base.is_empty() ) {
|
||||
if ( !is_valid() || !base.is_valid() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace
|
||||
[[maybe_unused]]
|
||||
void meta_invoke_function_1(benchmark::State &state) {
|
||||
meta::function f = meta_bench_scope.get_function("static_function_1");
|
||||
META_HPP_ASSERT(!f.is_empty());
|
||||
META_HPP_ASSERT(f.is_valid());
|
||||
|
||||
for ( auto _ : state ) {
|
||||
f(static_angle);
|
||||
@@ -138,7 +138,7 @@ namespace
|
||||
[[maybe_unused]]
|
||||
void meta_invoke_function_2(benchmark::State &state) {
|
||||
meta::function f = meta_bench_scope.get_function("static_function_2");
|
||||
META_HPP_ASSERT(!f.is_empty());
|
||||
META_HPP_ASSERT(f.is_valid());
|
||||
|
||||
for ( auto _ : state ) {
|
||||
f(static_angle, vmath::unit3_x<float>);
|
||||
@@ -148,7 +148,7 @@ namespace
|
||||
[[maybe_unused]]
|
||||
void meta_invoke_function_3(benchmark::State &state) {
|
||||
meta::function f = meta_bench_scope.get_function("static_function_3");
|
||||
META_HPP_ASSERT(!f.is_empty());
|
||||
META_HPP_ASSERT(f.is_valid());
|
||||
|
||||
for ( auto _ : state ) {
|
||||
f(static_angle, vmath::unit3_x<float>, 2.f);
|
||||
@@ -158,7 +158,7 @@ namespace
|
||||
[[maybe_unused]]
|
||||
void meta_invoke_function_4(benchmark::State &state) {
|
||||
meta::function f = meta_bench_scope.get_function("static_function_4");
|
||||
META_HPP_ASSERT(!f.is_empty());
|
||||
META_HPP_ASSERT(f.is_valid());
|
||||
|
||||
for ( auto _ : state ) {
|
||||
f(static_angle, vmath::unit3_x<float>, 2.f, vmath::midentity3<float>);
|
||||
|
||||
@@ -15,12 +15,12 @@ TEST_CASE("meta/meta_base/fixed_function") {
|
||||
{
|
||||
fixed_function<void()> ff;
|
||||
CHECK_FALSE(ff);
|
||||
CHECK(ff.is_empty());
|
||||
CHECK_FALSE(ff.is_valid());
|
||||
}
|
||||
{
|
||||
fixed_function<void()> ff = []{};
|
||||
CHECK(ff);
|
||||
CHECK_FALSE(ff.is_empty());
|
||||
CHECK(ff.is_valid());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ TEST_CASE("meta/meta_base/fixed_function") {
|
||||
|
||||
ff.reset();
|
||||
CHECK_FALSE(ff);
|
||||
CHECK(ff.is_empty());
|
||||
CHECK_FALSE(ff.is_valid());
|
||||
|
||||
ff = []{return 1;};
|
||||
CHECK(ff);
|
||||
CHECK_FALSE(ff.is_empty());
|
||||
CHECK(ff.is_valid());
|
||||
|
||||
CHECK(ff() == 1);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
memory_buffer buf;
|
||||
|
||||
CHECK(!buf);
|
||||
CHECK(buf.is_empty());
|
||||
CHECK_FALSE(buf.is_valid());
|
||||
|
||||
CHECK(buf.get_size() == 0);
|
||||
CHECK(buf.get_align() == std::align_val_t{});
|
||||
@@ -32,7 +32,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
|
||||
{
|
||||
CHECK(!buf1);
|
||||
CHECK(buf1.is_empty());
|
||||
CHECK_FALSE(buf1.is_valid());
|
||||
|
||||
CHECK(buf1.get_size() == 0);
|
||||
CHECK(buf1.get_align() == std::align_val_t{});
|
||||
@@ -43,7 +43,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
|
||||
{
|
||||
CHECK(buf2);
|
||||
CHECK(!buf2.is_empty());
|
||||
CHECK(buf2.is_valid());
|
||||
|
||||
CHECK(buf2.get_size() == 10);
|
||||
CHECK(buf2.get_align() == std::align_val_t{32});
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
memory_buffer buf{10, std::align_val_t{32}};
|
||||
|
||||
CHECK(buf);
|
||||
CHECK(!buf.is_empty());
|
||||
CHECK(buf.is_valid());
|
||||
|
||||
CHECK(buf.get_size() == 10);
|
||||
CHECK(buf.get_align() == std::align_val_t{32});
|
||||
@@ -82,7 +82,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
|
||||
{
|
||||
CHECK(!buf1);
|
||||
CHECK(buf1.is_empty());
|
||||
CHECK_FALSE(buf1.is_valid());
|
||||
|
||||
CHECK(buf1.get_size() == 0);
|
||||
CHECK(buf1.get_align() == std::align_val_t{});
|
||||
@@ -93,7 +93,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
|
||||
{
|
||||
CHECK(buf2);
|
||||
CHECK(!buf2.is_empty());
|
||||
CHECK(buf2.is_valid());
|
||||
|
||||
CHECK(buf2.get_size() == 10);
|
||||
CHECK(buf2.get_align() == std::align_val_t{32});
|
||||
@@ -112,7 +112,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
|
||||
{
|
||||
CHECK(!buf1);
|
||||
CHECK(buf1.is_empty());
|
||||
CHECK_FALSE(buf1.is_valid());
|
||||
|
||||
CHECK(buf1.get_size() == 0);
|
||||
CHECK(buf1.get_align() == std::align_val_t{});
|
||||
@@ -123,7 +123,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
|
||||
{
|
||||
CHECK(buf2);
|
||||
CHECK(!buf2.is_empty());
|
||||
CHECK(buf2.is_valid());
|
||||
|
||||
CHECK(buf2.get_size() == 10);
|
||||
CHECK(buf2.get_align() == std::align_val_t{32});
|
||||
@@ -138,7 +138,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
|
||||
buf.reset();
|
||||
|
||||
CHECK(!buf);
|
||||
CHECK(buf.is_empty());
|
||||
CHECK_FALSE(buf.is_valid());
|
||||
|
||||
CHECK(buf.get_size() == 0);
|
||||
CHECK(buf.get_align() == std::align_val_t{});
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST_CASE("meta/meta_states/evalue") {
|
||||
SUBCASE("") {
|
||||
const meta::evalue evalue;
|
||||
CHECK_FALSE(evalue);
|
||||
CHECK(evalue.is_empty());
|
||||
CHECK_FALSE(evalue.is_valid());
|
||||
CHECK(evalue == color_type.get_evalue("non-existent-evalue"));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ TEST_CASE("meta/meta_states/function") {
|
||||
SUBCASE("") {
|
||||
const meta::function func;
|
||||
CHECK_FALSE(func);
|
||||
CHECK(func.is_empty());
|
||||
CHECK_FALSE(func.is_valid());
|
||||
CHECK(func == ivec2_type.get_function("non-existent-function"));
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ TEST_CASE("meta/meta_states/member") {
|
||||
SUBCASE("") {
|
||||
const meta::member member;
|
||||
CHECK_FALSE(member);
|
||||
CHECK(member.is_empty());
|
||||
CHECK_FALSE(member.is_valid());
|
||||
CHECK(member == clazz_1_type.get_member("non-existent-member"));
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ TEST_CASE("meta/meta_states/method") {
|
||||
SUBCASE("") {
|
||||
const meta::method method;
|
||||
CHECK_FALSE(method);
|
||||
CHECK(method.is_empty());
|
||||
CHECK_FALSE(method.is_valid());
|
||||
CHECK(method == ct.get_method("non-existent-method"));
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("meta/meta_states/scope") {
|
||||
|
||||
const meta::scope math_scope = meta::resolve_scope("meta/meta_states/scope/math");
|
||||
REQUIRE(math_scope);
|
||||
REQUIRE(!math_scope.is_empty());
|
||||
REQUIRE(math_scope.is_valid());
|
||||
|
||||
CHECK(math_scope.get_name() == "meta/meta_states/scope/math");
|
||||
CHECK(math_scope.get_variables().size() == 2);
|
||||
@@ -66,7 +66,7 @@ TEST_CASE("meta/meta_states/scope") {
|
||||
SUBCASE("") {
|
||||
const meta::scope scope;
|
||||
CHECK_FALSE(scope);
|
||||
CHECK(scope.is_empty());
|
||||
CHECK_FALSE(scope.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("operators") {
|
||||
|
||||
@@ -68,7 +68,7 @@ TEST_CASE("meta/meta_states/variable") {
|
||||
SUBCASE("") {
|
||||
const meta::variable variable;
|
||||
CHECK_FALSE(variable);
|
||||
CHECK(variable.is_empty());
|
||||
CHECK_FALSE(variable.is_valid());
|
||||
CHECK(variable == clazz_1_type.get_variable("non-existent-variable"));
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ TEST_CASE("meta/meta_types/any_type") {
|
||||
SUBCASE("") {
|
||||
const meta::any_type type{};
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
|
||||
CHECK_FALSE(type.is_array());
|
||||
CHECK_FALSE(type.as_array());
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/array_type") {
|
||||
SUBCASE("") {
|
||||
const meta::array_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("int[]") {
|
||||
|
||||
@@ -30,7 +30,7 @@ TEST_CASE("meta/meta_types/function_type") {
|
||||
SUBCASE("") {
|
||||
const meta::function_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("arg_copy") {
|
||||
|
||||
@@ -21,7 +21,7 @@ TEST_CASE("meta/meta_types/member_type") {
|
||||
SUBCASE("") {
|
||||
const meta::member_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("int") {
|
||||
|
||||
@@ -33,7 +33,7 @@ TEST_CASE("meta/meta_types/method_type") {
|
||||
SUBCASE("") {
|
||||
const meta::method_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("ivec2::at") {
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/number_type") {
|
||||
SUBCASE("") {
|
||||
const meta::number_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("int") {
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/pointer_type") {
|
||||
SUBCASE("") {
|
||||
const meta::pointer_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("int*") {
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/reference_type") {
|
||||
SUBCASE("") {
|
||||
const meta::reference_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("int&") {
|
||||
|
||||
@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/void_type") {
|
||||
SUBCASE("") {
|
||||
const meta::void_type type;
|
||||
CHECK_FALSE(type);
|
||||
CHECK(type.is_empty());
|
||||
CHECK_FALSE(type.is_valid());
|
||||
}
|
||||
|
||||
SUBCASE("void") {
|
||||
|
||||
Reference in New Issue
Block a user