rewrite all "is_valid" methods to "is_empty"

This commit is contained in:
BlackMATov
2023-02-17 03:26:59 +07:00
parent c222a3a6a3
commit 2f3a6740b7
23 changed files with 77 additions and 77 deletions

View File

@@ -433,12 +433,12 @@ namespace meta_hpp::detail
return *this;
}
[[nodiscard]] bool is_valid() const noexcept {
return vtable_ != nullptr;
[[nodiscard]] bool is_empty() const noexcept {
return vtable_ == nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
return is_valid();
return vtable_ != nullptr;
}
R operator()(Args... args) const {
@@ -1080,12 +1080,12 @@ namespace meta_hpp::detail
reset();
}
[[nodiscard]] bool is_valid() const noexcept {
return data_ != nullptr;
[[nodiscard]] bool is_empty() const noexcept {
return data_ == nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
return is_valid();
return data_ != nullptr;
}
void reset() noexcept {
@@ -2227,8 +2227,8 @@ namespace meta_hpp
type_base& operator=(type_base&&) noexcept = default;
type_base& operator=(const type_base&) = default;
[[nodiscard]] bool is_valid() const noexcept {
return data_ != nullptr;
[[nodiscard]] bool is_empty() const noexcept {
return data_ == nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
@@ -2489,7 +2489,7 @@ namespace std
template < meta_hpp::detail::type_family Type >
struct hash<Type> {
size_t operator()(const Type& type) const noexcept {
return type.is_valid() ? type.get_id().get_hash() : 0;
return type.is_empty() ? 0 : type.get_id().get_hash();
}
};
}
@@ -2498,15 +2498,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_valid() == r.is_valid() && (!l.is_valid() || l.get_id() == r.get_id());
return l.is_empty() == r.is_empty() && (l.is_empty() || 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_valid() <=> r.is_valid()}; cmp != std::strong_ordering::equal ) {
if ( const std::strong_ordering cmp{!l.is_empty() <=> !r.is_empty()}; cmp != std::strong_ordering::equal ) {
return cmp;
}
return l.is_valid() ? l.get_id() <=> r.get_id() : std::strong_ordering::equal;
return l.is_empty() ? std::strong_ordering::equal : l.get_id() <=> r.get_id();
}
}
@@ -2514,12 +2514,12 @@ namespace meta_hpp
{
template < detail::type_family L >
[[nodiscard]] bool operator==(const L& l, type_id r) noexcept {
return l.is_valid() && l.get_id() == r;
return !l.is_empty() && l.get_id() == r;
}
template < detail::type_family L >
[[nodiscard]] std::strong_ordering operator<=>(const L& l, type_id r) noexcept {
return l.is_valid() ? l.get_id() <=> r : std::strong_ordering::less;
return !l.is_empty() ? l.get_id() <=> r : std::strong_ordering::less;
}
}
@@ -3209,8 +3209,8 @@ namespace meta_hpp
state_base& operator=(state_base&&) noexcept = default;
state_base& operator=(const state_base&) = default;
[[nodiscard]] bool is_valid() const noexcept {
return state_ != nullptr;
[[nodiscard]] bool is_empty() const noexcept {
return state_ == nullptr;
}
[[nodiscard]] explicit operator bool() const noexcept {
@@ -3466,7 +3466,7 @@ namespace std
template < meta_hpp::detail::state_family State >
struct hash<State> {
size_t operator()(const State& state) const noexcept {
return state.is_valid() ? state.get_index().get_hash() : 0;
return state.is_empty() ? 0 : state.get_index().get_hash();
}
};
}
@@ -3475,15 +3475,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_valid() == r.is_valid() && (!l.is_valid() || l.get_index() == r.get_index());
return l.is_empty() == r.is_empty() && (l.is_empty() || 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_valid() <=> r.is_valid()}; cmp != std::strong_ordering::equal ) {
if ( const std::strong_ordering cmp{!l.is_empty() <=> !r.is_empty()}; cmp != std::strong_ordering::equal ) {
return cmp;
}
return l.is_valid() ? l.get_index() <=> r.get_index() : std::strong_ordering::equal;
return l.is_empty() ? std::strong_ordering::equal : l.get_index() <=> r.get_index();
}
}
@@ -3491,12 +3491,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_valid() && l.get_index() == r;
return !l.is_empty() && 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_valid() ? l.get_index() <=> r : std::strong_ordering::less;
return !l.is_empty() ? l.get_index() <=> r : std::strong_ordering::less;
}
}
@@ -7602,7 +7602,7 @@ namespace meta_hpp
}
inline bool class_type::is_base_of(const class_type& derived) const noexcept {
if ( !is_valid() || !derived.is_valid() ) {
if ( is_empty() || derived.is_empty() ) {
return false;
}
@@ -7626,7 +7626,7 @@ namespace meta_hpp
}
inline bool class_type::is_derived_from(const class_type& base) const noexcept {
if ( !is_valid() || !base.is_valid() ) {
if ( is_empty() || base.is_empty() ) {
return false;
}

View File

@@ -15,12 +15,12 @@ TEST_CASE("meta/meta_base/fixed_function") {
{
fixed_function<void()> ff;
CHECK_FALSE(ff);
CHECK_FALSE(ff.is_valid());
CHECK(ff.is_empty());
}
{
fixed_function<void()> ff = []{};
CHECK(ff);
CHECK(ff.is_valid());
CHECK_FALSE(ff.is_empty());
}
}
@@ -46,11 +46,11 @@ TEST_CASE("meta/meta_base/fixed_function") {
ff.reset();
CHECK_FALSE(ff);
CHECK_FALSE(ff.is_valid());
CHECK(ff.is_empty());
ff = []{return 1;};
CHECK(ff);
CHECK(ff.is_valid());
CHECK_FALSE(ff.is_empty());
CHECK(ff() == 1);
}

View File

@@ -15,7 +15,7 @@ TEST_CASE("meta/meta_base/memory_buffer") {
memory_buffer buf;
CHECK(!buf);
CHECK(!buf.is_valid());
CHECK(buf.is_empty());
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_valid());
CHECK(buf1.is_empty());
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_valid());
CHECK(!buf2.is_empty());
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_valid());
CHECK(!buf.is_empty());
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_valid());
CHECK(buf1.is_empty());
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_valid());
CHECK(!buf2.is_empty());
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_valid());
CHECK(buf1.is_empty());
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_valid());
CHECK(!buf2.is_empty());
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_valid());
CHECK(buf.is_empty());
CHECK(buf.get_size() == 0);
CHECK(buf.get_align() == std::align_val_t{});

View File

@@ -34,7 +34,7 @@ TEST_CASE("meta/meta_states/evalue") {
SUBCASE("") {
const meta::evalue evalue;
CHECK_FALSE(evalue);
CHECK_FALSE(evalue.is_valid());
CHECK(evalue.is_empty());
CHECK(evalue == color_type.get_evalue("non-existent-evalue"));
}

View File

@@ -51,7 +51,7 @@ TEST_CASE("meta/meta_states/function") {
SUBCASE("") {
const meta::function func;
CHECK_FALSE(func);
CHECK_FALSE(func.is_valid());
CHECK(func.is_empty());
CHECK(func == ivec2_type.get_function("non-existent-function"));
}

View File

@@ -38,7 +38,7 @@ TEST_CASE("meta/meta_states/member") {
SUBCASE("") {
const meta::member member;
CHECK_FALSE(member);
CHECK_FALSE(member.is_valid());
CHECK(member.is_empty());
CHECK(member == clazz_1_type.get_member("non-existent-member"));
}

View File

@@ -102,7 +102,7 @@ TEST_CASE("meta/meta_states/method") {
SUBCASE("") {
const meta::method method;
CHECK_FALSE(method);
CHECK_FALSE(method.is_valid());
CHECK(method.is_empty());
CHECK(method == ct.get_method("non-existent-method"));
}

View File

@@ -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_valid());
REQUIRE(!math_scope.is_empty());
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_FALSE(scope.is_valid());
CHECK(scope.is_empty());
}
SUBCASE("operators") {

View File

@@ -68,7 +68,7 @@ TEST_CASE("meta/meta_states/variable") {
SUBCASE("") {
const meta::variable variable;
CHECK_FALSE(variable);
CHECK_FALSE(variable.is_valid());
CHECK(variable.is_empty());
CHECK(variable == clazz_1_type.get_variable("non-existent-variable"));
}

View File

@@ -39,7 +39,7 @@ TEST_CASE("meta/meta_types/any_type") {
SUBCASE("") {
const meta::any_type type{};
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
CHECK_FALSE(type.is_array());
CHECK_FALSE(type.as_array());

View File

@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/array_type") {
SUBCASE("") {
const meta::array_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("int[]") {

View File

@@ -30,7 +30,7 @@ TEST_CASE("meta/meta_types/function_type") {
SUBCASE("") {
const meta::function_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("arg_copy") {

View File

@@ -21,7 +21,7 @@ TEST_CASE("meta/meta_types/member_type") {
SUBCASE("") {
const meta::member_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("int") {

View File

@@ -33,7 +33,7 @@ TEST_CASE("meta/meta_types/method_type") {
SUBCASE("") {
const meta::method_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("ivec2::at") {

View File

@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/number_type") {
SUBCASE("") {
const meta::number_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("int") {

View File

@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/pointer_type") {
SUBCASE("") {
const meta::pointer_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("int*") {

View File

@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/reference_type") {
SUBCASE("") {
const meta::reference_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("int&") {

View File

@@ -13,7 +13,7 @@ TEST_CASE("meta/meta_types/void_type") {
SUBCASE("") {
const meta::void_type type;
CHECK_FALSE(type);
CHECK_FALSE(type.is_valid());
CHECK(type.is_empty());
}
SUBCASE("void") {