states with their indices compare operators

This commit is contained in:
BlackMATov
2023-01-13 06:50:18 +07:00
parent 7fcfef63f7
commit eaf84e4ba5
4 changed files with 247 additions and 14 deletions

View File

@@ -105,6 +105,8 @@ namespace meta_hpp
{
class argument final {
public:
using index_type = argument_index;
explicit argument() = default;
explicit argument(detail::argument_state_ptr state) noexcept;
argument& operator=(detail::argument_state_ptr state) noexcept;
@@ -126,8 +128,10 @@ namespace meta_hpp
class constructor final {
public:
using index_type = constructor_index;
explicit constructor() = default;
explicit constructor(detail::constructor_state_ptr state) noexcept;
constructor(detail::constructor_state_ptr state) noexcept;
constructor& operator=(detail::constructor_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -159,8 +163,10 @@ namespace meta_hpp
class destructor final {
public:
using index_type = destructor_index;
explicit destructor() = default;
explicit destructor(detail::destructor_state_ptr state) noexcept;
destructor(detail::destructor_state_ptr state) noexcept;
destructor& operator=(detail::destructor_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -182,8 +188,10 @@ namespace meta_hpp
class evalue final {
public:
using index_type = evalue_index;
explicit evalue() = default;
explicit evalue(detail::evalue_state_ptr state) noexcept;
evalue(detail::evalue_state_ptr state) noexcept;
evalue& operator=(detail::evalue_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -210,8 +218,10 @@ namespace meta_hpp
class function final {
public:
using index_type = function_index;
explicit function() = default;
explicit function(detail::function_state_ptr state) noexcept;
function(detail::function_state_ptr state) noexcept;
function& operator=(detail::function_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -244,8 +254,10 @@ namespace meta_hpp
class member final {
public:
using index_type = member_index;
explicit member() = default;
explicit member(detail::member_state_ptr state) noexcept;
member(detail::member_state_ptr state) noexcept;
member& operator=(detail::member_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -290,8 +302,10 @@ namespace meta_hpp
class method final {
public:
using index_type = method_index;
explicit method() = default;
explicit method(detail::method_state_ptr state) noexcept;
method(detail::method_state_ptr state) noexcept;
method& operator=(detail::method_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -324,6 +338,8 @@ namespace meta_hpp
class scope final {
public:
using index_type = scope_index;
explicit scope() = default;
explicit scope(detail::scope_state_ptr state) noexcept;
scope& operator=(detail::scope_state_ptr state) noexcept;
@@ -357,8 +373,10 @@ namespace meta_hpp
class variable final {
public:
using index_type = variable_index;
explicit variable() = default;
explicit variable(detail::variable_state_ptr state) noexcept;
variable(detail::variable_state_ptr state) noexcept;
variable& operator=(detail::variable_state_ptr state) noexcept;
[[nodiscard]] bool is_valid() const noexcept;
@@ -428,6 +446,45 @@ namespace meta_hpp
}
}
namespace meta_hpp
{
template < detail::state_family T, typename U >
requires std::is_same_v<U, typename T::index_type>
[[nodiscard]] bool operator<(const T& l, const U& r) noexcept {
return !static_cast<bool>(l) || l.get_index() < r;
}
template < typename T, detail::state_family U >
requires std::is_same_v<T, typename U::index_type>
[[nodiscard]] bool operator<(const T& l, const U& r) noexcept {
return static_cast<bool>(r) && l < r.get_index();
}
template < detail::state_family T, typename U >
requires std::is_same_v<U, typename T::index_type>
[[nodiscard]] bool operator==(const T& l, const U& r) noexcept {
return static_cast<bool>(l) || l.get_index() == r;
}
template < typename T, detail::state_family U >
requires std::is_same_v<T, typename U::index_type>
[[nodiscard]] bool operator==(const T& l, const U& r) noexcept {
return static_cast<bool>(r) && l == r.get_index();
}
template < detail::state_family T, typename U >
requires std::is_same_v<U, typename T::index_type>
[[nodiscard]] bool operator!=(const T& l, const U& r) noexcept {
return !(l == r);
}
template < typename T, detail::state_family U >
requires std::is_same_v<T, typename U::index_type>
[[nodiscard]] bool operator!=(const T& l, const U& r) noexcept {
return !(l == r);
}
}
namespace meta_hpp::detail
{
struct argument_state final {