mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
template is/as for any_type
This commit is contained in:
@@ -1998,6 +1998,7 @@ namespace meta_hpp
|
|||||||
using data_ptr = detail::type_data_base*;
|
using data_ptr = detail::type_data_base*;
|
||||||
|
|
||||||
any_type() = default;
|
any_type() = default;
|
||||||
|
any_type(data_ptr data);
|
||||||
|
|
||||||
[[nodiscard]] bool is_valid() const noexcept;
|
[[nodiscard]] bool is_valid() const noexcept;
|
||||||
[[nodiscard]] explicit operator bool() const noexcept;
|
[[nodiscard]] explicit operator bool() const noexcept;
|
||||||
@@ -2021,6 +2022,12 @@ namespace meta_hpp
|
|||||||
any_type(const reference_type& other) noexcept;
|
any_type(const reference_type& other) noexcept;
|
||||||
any_type(const void_type& other) noexcept;
|
any_type(const void_type& other) noexcept;
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
[[nodiscard]] bool is() const noexcept;
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
[[nodiscard]] Type as() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] bool is_array() const noexcept;
|
[[nodiscard]] bool is_array() const noexcept;
|
||||||
[[nodiscard]] bool is_class() const noexcept;
|
[[nodiscard]] bool is_class() const noexcept;
|
||||||
[[nodiscard]] bool is_constructor() const noexcept;
|
[[nodiscard]] bool is_constructor() const noexcept;
|
||||||
@@ -2057,6 +2064,7 @@ namespace meta_hpp
|
|||||||
class array_type final {
|
class array_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::array_type_data*;
|
using data_ptr = detail::array_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::array_};
|
||||||
|
|
||||||
array_type() = default;
|
array_type() = default;
|
||||||
array_type(data_ptr data);
|
array_type(data_ptr data);
|
||||||
@@ -2079,6 +2087,7 @@ namespace meta_hpp
|
|||||||
class class_type final {
|
class class_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::class_type_data*;
|
using data_ptr = detail::class_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::class_};
|
||||||
|
|
||||||
class_type() = default;
|
class_type() = default;
|
||||||
class_type(data_ptr data);
|
class_type(data_ptr data);
|
||||||
@@ -2160,6 +2169,7 @@ namespace meta_hpp
|
|||||||
class constructor_type final {
|
class constructor_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::constructor_type_data*;
|
using data_ptr = detail::constructor_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::constructor_};
|
||||||
|
|
||||||
constructor_type() = default;
|
constructor_type() = default;
|
||||||
constructor_type(data_ptr data);
|
constructor_type(data_ptr data);
|
||||||
@@ -2184,6 +2194,7 @@ namespace meta_hpp
|
|||||||
class destructor_type final {
|
class destructor_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::destructor_type_data*;
|
using data_ptr = detail::destructor_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::destructor_};
|
||||||
|
|
||||||
destructor_type() = default;
|
destructor_type() = default;
|
||||||
destructor_type(data_ptr data);
|
destructor_type(data_ptr data);
|
||||||
@@ -2205,6 +2216,7 @@ namespace meta_hpp
|
|||||||
class enum_type final {
|
class enum_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::enum_type_data*;
|
using data_ptr = detail::enum_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::enum_};
|
||||||
|
|
||||||
enum_type() = default;
|
enum_type() = default;
|
||||||
enum_type(data_ptr data);
|
enum_type(data_ptr data);
|
||||||
@@ -2237,6 +2249,7 @@ namespace meta_hpp
|
|||||||
class function_type final {
|
class function_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::function_type_data*;
|
using data_ptr = detail::function_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::function_};
|
||||||
|
|
||||||
function_type() = default;
|
function_type() = default;
|
||||||
function_type(data_ptr data);
|
function_type(data_ptr data);
|
||||||
@@ -2261,6 +2274,7 @@ namespace meta_hpp
|
|||||||
class member_type final {
|
class member_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::member_type_data*;
|
using data_ptr = detail::member_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::member_};
|
||||||
|
|
||||||
member_type() = default;
|
member_type() = default;
|
||||||
member_type(data_ptr data);
|
member_type(data_ptr data);
|
||||||
@@ -2283,6 +2297,7 @@ namespace meta_hpp
|
|||||||
class method_type final {
|
class method_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::method_type_data*;
|
using data_ptr = detail::method_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::method_};
|
||||||
|
|
||||||
method_type() = default;
|
method_type() = default;
|
||||||
method_type(data_ptr data);
|
method_type(data_ptr data);
|
||||||
@@ -2308,6 +2323,7 @@ namespace meta_hpp
|
|||||||
class nullptr_type final {
|
class nullptr_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::nullptr_type_data*;
|
using data_ptr = detail::nullptr_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::nullptr_};
|
||||||
|
|
||||||
nullptr_type() = default;
|
nullptr_type() = default;
|
||||||
nullptr_type(data_ptr data);
|
nullptr_type(data_ptr data);
|
||||||
@@ -2326,6 +2342,7 @@ namespace meta_hpp
|
|||||||
class number_type final {
|
class number_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::number_type_data*;
|
using data_ptr = detail::number_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::number_};
|
||||||
|
|
||||||
number_type() = default;
|
number_type() = default;
|
||||||
number_type(data_ptr data);
|
number_type(data_ptr data);
|
||||||
@@ -2348,6 +2365,7 @@ namespace meta_hpp
|
|||||||
class pointer_type final {
|
class pointer_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::pointer_type_data*;
|
using data_ptr = detail::pointer_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::pointer_};
|
||||||
|
|
||||||
pointer_type() = default;
|
pointer_type() = default;
|
||||||
pointer_type(data_ptr data);
|
pointer_type(data_ptr data);
|
||||||
@@ -2369,6 +2387,7 @@ namespace meta_hpp
|
|||||||
class reference_type final {
|
class reference_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::reference_type_data*;
|
using data_ptr = detail::reference_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::reference_};
|
||||||
|
|
||||||
reference_type() = default;
|
reference_type() = default;
|
||||||
reference_type(data_ptr data);
|
reference_type(data_ptr data);
|
||||||
@@ -2390,6 +2409,7 @@ namespace meta_hpp
|
|||||||
class void_type final {
|
class void_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::void_type_data*;
|
using data_ptr = detail::void_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::void_};
|
||||||
|
|
||||||
void_type() = default;
|
void_type() = default;
|
||||||
void_type(data_ptr data);
|
void_type(data_ptr data);
|
||||||
@@ -7698,6 +7718,9 @@ namespace meta_hpp
|
|||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
{
|
{
|
||||||
|
inline any_type::any_type(data_ptr data)
|
||||||
|
: data_{data} {}
|
||||||
|
|
||||||
inline bool any_type::is_valid() const noexcept {
|
inline bool any_type::is_valid() const noexcept {
|
||||||
return data_ != nullptr;
|
return data_ != nullptr;
|
||||||
}
|
}
|
||||||
@@ -7757,121 +7780,122 @@ namespace meta_hpp
|
|||||||
inline any_type::any_type(const void_type& other) noexcept
|
inline any_type::any_type(const void_type& other) noexcept
|
||||||
: data_{detail::type_access(other)} {}
|
: data_{detail::type_access(other)} {}
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
bool any_type::is() const noexcept {
|
||||||
|
if constexpr ( std::is_same_v<Type, any_type> ) {
|
||||||
|
return data_ != nullptr;
|
||||||
|
} else {
|
||||||
|
return data_ != nullptr && data_->kind == Type::kind;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
Type any_type::as() const noexcept {
|
||||||
|
return is<Type>() ? Type{static_cast<typename Type::data_ptr>(data_)} : Type{};
|
||||||
|
}
|
||||||
|
|
||||||
inline bool any_type::is_array() const noexcept {
|
inline bool any_type::is_array() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::array_;
|
return is<array_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_class() const noexcept {
|
inline bool any_type::is_class() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::class_;
|
return is<class_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_constructor() const noexcept {
|
inline bool any_type::is_constructor() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::constructor_;
|
return is<constructor_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_destructor() const noexcept {
|
inline bool any_type::is_destructor() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::destructor_;
|
return is<destructor_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_enum() const noexcept {
|
inline bool any_type::is_enum() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::enum_;
|
return is<enum_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_function() const noexcept {
|
inline bool any_type::is_function() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::function_;
|
return is<function_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_member() const noexcept {
|
inline bool any_type::is_member() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::member_;
|
return is<member_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_method() const noexcept {
|
inline bool any_type::is_method() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::method_;
|
return is<method_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_nullptr() const noexcept {
|
inline bool any_type::is_nullptr() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::nullptr_;
|
return is<nullptr_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_number() const noexcept {
|
inline bool any_type::is_number() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::number_;
|
return is<number_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_pointer() const noexcept {
|
inline bool any_type::is_pointer() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::pointer_;
|
return is<pointer_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_reference() const noexcept {
|
inline bool any_type::is_reference() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::reference_;
|
return is<reference_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_void() const noexcept {
|
inline bool any_type::is_void() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::void_;
|
return is<void_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline array_type any_type::as_array() const noexcept {
|
inline array_type any_type::as_array() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<array_type>();
|
||||||
return is_array() ? array_type{static_cast<detail::array_type_data*>(data_)} : array_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline class_type any_type::as_class() const noexcept {
|
inline class_type any_type::as_class() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<class_type>();
|
||||||
return is_class() ? class_type{static_cast<detail::class_type_data*>(data_)} : class_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constructor_type any_type::as_constructor() const noexcept {
|
inline constructor_type any_type::as_constructor() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<constructor_type>();
|
||||||
return is_constructor() ? constructor_type{static_cast<detail::constructor_type_data*>(data_)} : constructor_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline destructor_type any_type::as_destructor() const noexcept {
|
inline destructor_type any_type::as_destructor() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<destructor_type>();
|
||||||
return is_destructor() ? destructor_type{static_cast<detail::destructor_type_data*>(data_)} : destructor_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline enum_type any_type::as_enum() const noexcept {
|
inline enum_type any_type::as_enum() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<enum_type>();
|
||||||
return is_enum() ? enum_type{static_cast<detail::enum_type_data*>(data_)} : enum_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline function_type any_type::as_function() const noexcept {
|
inline function_type any_type::as_function() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<function_type>();
|
||||||
return is_function() ? function_type{static_cast<detail::function_type_data*>(data_)} : function_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline member_type any_type::as_member() const noexcept {
|
inline member_type any_type::as_member() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<member_type>();
|
||||||
return is_member() ? member_type{static_cast<detail::member_type_data*>(data_)} : member_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline method_type any_type::as_method() const noexcept {
|
inline method_type any_type::as_method() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<method_type>();
|
||||||
return is_method() ? method_type{static_cast<detail::method_type_data*>(data_)} : method_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nullptr_type any_type::as_nullptr() const noexcept {
|
inline nullptr_type any_type::as_nullptr() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<nullptr_type>();
|
||||||
return is_nullptr() ? nullptr_type{static_cast<detail::nullptr_type_data*>(data_)} : nullptr_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline number_type any_type::as_number() const noexcept {
|
inline number_type any_type::as_number() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<number_type>();
|
||||||
return is_number() ? number_type{static_cast<detail::number_type_data*>(data_)} : number_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline pointer_type any_type::as_pointer() const noexcept {
|
inline pointer_type any_type::as_pointer() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<pointer_type>();
|
||||||
return is_pointer() ? pointer_type{static_cast<detail::pointer_type_data*>(data_)} : pointer_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline reference_type any_type::as_reference() const noexcept {
|
inline reference_type any_type::as_reference() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<reference_type>();
|
||||||
return is_reference() ? reference_type{static_cast<detail::reference_type_data*>(data_)} : reference_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void_type any_type::as_void() const noexcept {
|
inline void_type any_type::as_void() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<void_type>();
|
||||||
return is_void() ? void_type{static_cast<detail::void_type_data*>(data_)} : void_type{};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,4 +256,12 @@ TEST_CASE("meta/meta_types/any_type") {
|
|||||||
REQUIRE(specific_type);
|
REQUIRE(specific_type);
|
||||||
CHECK(specific_type.get_id() == type.get_id());
|
CHECK(specific_type.get_id() == type.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUBCASE("is/as") {
|
||||||
|
const meta::any_type type{meta::resolve_type<class_t>()};
|
||||||
|
CHECK(type.is<meta::any_type>());
|
||||||
|
|
||||||
|
const meta::any_type type2{type.as<meta::any_type>()};
|
||||||
|
CHECK(type2.as<meta::class_type>() == meta::resolve_type<class_t>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ namespace meta_hpp
|
|||||||
using data_ptr = detail::type_data_base*;
|
using data_ptr = detail::type_data_base*;
|
||||||
|
|
||||||
any_type() = default;
|
any_type() = default;
|
||||||
|
any_type(data_ptr data);
|
||||||
|
|
||||||
[[nodiscard]] bool is_valid() const noexcept;
|
[[nodiscard]] bool is_valid() const noexcept;
|
||||||
[[nodiscard]] explicit operator bool() const noexcept;
|
[[nodiscard]] explicit operator bool() const noexcept;
|
||||||
@@ -88,6 +89,12 @@ namespace meta_hpp
|
|||||||
any_type(const reference_type& other) noexcept;
|
any_type(const reference_type& other) noexcept;
|
||||||
any_type(const void_type& other) noexcept;
|
any_type(const void_type& other) noexcept;
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
[[nodiscard]] bool is() const noexcept;
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
[[nodiscard]] Type as() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] bool is_array() const noexcept;
|
[[nodiscard]] bool is_array() const noexcept;
|
||||||
[[nodiscard]] bool is_class() const noexcept;
|
[[nodiscard]] bool is_class() const noexcept;
|
||||||
[[nodiscard]] bool is_constructor() const noexcept;
|
[[nodiscard]] bool is_constructor() const noexcept;
|
||||||
@@ -124,6 +131,7 @@ namespace meta_hpp
|
|||||||
class array_type final {
|
class array_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::array_type_data*;
|
using data_ptr = detail::array_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::array_};
|
||||||
|
|
||||||
array_type() = default;
|
array_type() = default;
|
||||||
array_type(data_ptr data);
|
array_type(data_ptr data);
|
||||||
@@ -146,6 +154,7 @@ namespace meta_hpp
|
|||||||
class class_type final {
|
class class_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::class_type_data*;
|
using data_ptr = detail::class_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::class_};
|
||||||
|
|
||||||
class_type() = default;
|
class_type() = default;
|
||||||
class_type(data_ptr data);
|
class_type(data_ptr data);
|
||||||
@@ -227,6 +236,7 @@ namespace meta_hpp
|
|||||||
class constructor_type final {
|
class constructor_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::constructor_type_data*;
|
using data_ptr = detail::constructor_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::constructor_};
|
||||||
|
|
||||||
constructor_type() = default;
|
constructor_type() = default;
|
||||||
constructor_type(data_ptr data);
|
constructor_type(data_ptr data);
|
||||||
@@ -251,6 +261,7 @@ namespace meta_hpp
|
|||||||
class destructor_type final {
|
class destructor_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::destructor_type_data*;
|
using data_ptr = detail::destructor_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::destructor_};
|
||||||
|
|
||||||
destructor_type() = default;
|
destructor_type() = default;
|
||||||
destructor_type(data_ptr data);
|
destructor_type(data_ptr data);
|
||||||
@@ -272,6 +283,7 @@ namespace meta_hpp
|
|||||||
class enum_type final {
|
class enum_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::enum_type_data*;
|
using data_ptr = detail::enum_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::enum_};
|
||||||
|
|
||||||
enum_type() = default;
|
enum_type() = default;
|
||||||
enum_type(data_ptr data);
|
enum_type(data_ptr data);
|
||||||
@@ -304,6 +316,7 @@ namespace meta_hpp
|
|||||||
class function_type final {
|
class function_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::function_type_data*;
|
using data_ptr = detail::function_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::function_};
|
||||||
|
|
||||||
function_type() = default;
|
function_type() = default;
|
||||||
function_type(data_ptr data);
|
function_type(data_ptr data);
|
||||||
@@ -328,6 +341,7 @@ namespace meta_hpp
|
|||||||
class member_type final {
|
class member_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::member_type_data*;
|
using data_ptr = detail::member_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::member_};
|
||||||
|
|
||||||
member_type() = default;
|
member_type() = default;
|
||||||
member_type(data_ptr data);
|
member_type(data_ptr data);
|
||||||
@@ -350,6 +364,7 @@ namespace meta_hpp
|
|||||||
class method_type final {
|
class method_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::method_type_data*;
|
using data_ptr = detail::method_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::method_};
|
||||||
|
|
||||||
method_type() = default;
|
method_type() = default;
|
||||||
method_type(data_ptr data);
|
method_type(data_ptr data);
|
||||||
@@ -375,6 +390,7 @@ namespace meta_hpp
|
|||||||
class nullptr_type final {
|
class nullptr_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::nullptr_type_data*;
|
using data_ptr = detail::nullptr_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::nullptr_};
|
||||||
|
|
||||||
nullptr_type() = default;
|
nullptr_type() = default;
|
||||||
nullptr_type(data_ptr data);
|
nullptr_type(data_ptr data);
|
||||||
@@ -393,6 +409,7 @@ namespace meta_hpp
|
|||||||
class number_type final {
|
class number_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::number_type_data*;
|
using data_ptr = detail::number_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::number_};
|
||||||
|
|
||||||
number_type() = default;
|
number_type() = default;
|
||||||
number_type(data_ptr data);
|
number_type(data_ptr data);
|
||||||
@@ -415,6 +432,7 @@ namespace meta_hpp
|
|||||||
class pointer_type final {
|
class pointer_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::pointer_type_data*;
|
using data_ptr = detail::pointer_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::pointer_};
|
||||||
|
|
||||||
pointer_type() = default;
|
pointer_type() = default;
|
||||||
pointer_type(data_ptr data);
|
pointer_type(data_ptr data);
|
||||||
@@ -436,6 +454,7 @@ namespace meta_hpp
|
|||||||
class reference_type final {
|
class reference_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::reference_type_data*;
|
using data_ptr = detail::reference_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::reference_};
|
||||||
|
|
||||||
reference_type() = default;
|
reference_type() = default;
|
||||||
reference_type(data_ptr data);
|
reference_type(data_ptr data);
|
||||||
@@ -457,6 +476,7 @@ namespace meta_hpp
|
|||||||
class void_type final {
|
class void_type final {
|
||||||
public:
|
public:
|
||||||
using data_ptr = detail::void_type_data*;
|
using data_ptr = detail::void_type_data*;
|
||||||
|
inline static constexpr type_kind kind{type_kind::void_};
|
||||||
|
|
||||||
void_type() = default;
|
void_type() = default;
|
||||||
void_type(data_ptr data);
|
void_type(data_ptr data);
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace meta_hpp
|
namespace meta_hpp
|
||||||
{
|
{
|
||||||
|
inline any_type::any_type(data_ptr data)
|
||||||
|
: data_{data} {}
|
||||||
|
|
||||||
inline bool any_type::is_valid() const noexcept {
|
inline bool any_type::is_valid() const noexcept {
|
||||||
return data_ != nullptr;
|
return data_ != nullptr;
|
||||||
}
|
}
|
||||||
@@ -70,120 +73,121 @@ namespace meta_hpp
|
|||||||
inline any_type::any_type(const void_type& other) noexcept
|
inline any_type::any_type(const void_type& other) noexcept
|
||||||
: data_{detail::type_access(other)} {}
|
: data_{detail::type_access(other)} {}
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
bool any_type::is() const noexcept {
|
||||||
|
if constexpr ( std::is_same_v<Type, any_type> ) {
|
||||||
|
return data_ != nullptr;
|
||||||
|
} else {
|
||||||
|
return data_ != nullptr && data_->kind == Type::kind;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template < detail::type_family Type >
|
||||||
|
Type any_type::as() const noexcept {
|
||||||
|
return is<Type>() ? Type{static_cast<typename Type::data_ptr>(data_)} : Type{};
|
||||||
|
}
|
||||||
|
|
||||||
inline bool any_type::is_array() const noexcept {
|
inline bool any_type::is_array() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::array_;
|
return is<array_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_class() const noexcept {
|
inline bool any_type::is_class() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::class_;
|
return is<class_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_constructor() const noexcept {
|
inline bool any_type::is_constructor() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::constructor_;
|
return is<constructor_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_destructor() const noexcept {
|
inline bool any_type::is_destructor() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::destructor_;
|
return is<destructor_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_enum() const noexcept {
|
inline bool any_type::is_enum() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::enum_;
|
return is<enum_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_function() const noexcept {
|
inline bool any_type::is_function() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::function_;
|
return is<function_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_member() const noexcept {
|
inline bool any_type::is_member() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::member_;
|
return is<member_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_method() const noexcept {
|
inline bool any_type::is_method() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::method_;
|
return is<method_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_nullptr() const noexcept {
|
inline bool any_type::is_nullptr() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::nullptr_;
|
return is<nullptr_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_number() const noexcept {
|
inline bool any_type::is_number() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::number_;
|
return is<number_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_pointer() const noexcept {
|
inline bool any_type::is_pointer() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::pointer_;
|
return is<pointer_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_reference() const noexcept {
|
inline bool any_type::is_reference() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::reference_;
|
return is<reference_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool any_type::is_void() const noexcept {
|
inline bool any_type::is_void() const noexcept {
|
||||||
return is_valid() && data_->kind == type_kind::void_;
|
return is<void_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline array_type any_type::as_array() const noexcept {
|
inline array_type any_type::as_array() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<array_type>();
|
||||||
return is_array() ? array_type{static_cast<detail::array_type_data*>(data_)} : array_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline class_type any_type::as_class() const noexcept {
|
inline class_type any_type::as_class() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<class_type>();
|
||||||
return is_class() ? class_type{static_cast<detail::class_type_data*>(data_)} : class_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constructor_type any_type::as_constructor() const noexcept {
|
inline constructor_type any_type::as_constructor() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<constructor_type>();
|
||||||
return is_constructor() ? constructor_type{static_cast<detail::constructor_type_data*>(data_)} : constructor_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline destructor_type any_type::as_destructor() const noexcept {
|
inline destructor_type any_type::as_destructor() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<destructor_type>();
|
||||||
return is_destructor() ? destructor_type{static_cast<detail::destructor_type_data*>(data_)} : destructor_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline enum_type any_type::as_enum() const noexcept {
|
inline enum_type any_type::as_enum() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<enum_type>();
|
||||||
return is_enum() ? enum_type{static_cast<detail::enum_type_data*>(data_)} : enum_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline function_type any_type::as_function() const noexcept {
|
inline function_type any_type::as_function() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<function_type>();
|
||||||
return is_function() ? function_type{static_cast<detail::function_type_data*>(data_)} : function_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline member_type any_type::as_member() const noexcept {
|
inline member_type any_type::as_member() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<member_type>();
|
||||||
return is_member() ? member_type{static_cast<detail::member_type_data*>(data_)} : member_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline method_type any_type::as_method() const noexcept {
|
inline method_type any_type::as_method() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<method_type>();
|
||||||
return is_method() ? method_type{static_cast<detail::method_type_data*>(data_)} : method_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nullptr_type any_type::as_nullptr() const noexcept {
|
inline nullptr_type any_type::as_nullptr() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<nullptr_type>();
|
||||||
return is_nullptr() ? nullptr_type{static_cast<detail::nullptr_type_data*>(data_)} : nullptr_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline number_type any_type::as_number() const noexcept {
|
inline number_type any_type::as_number() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<number_type>();
|
||||||
return is_number() ? number_type{static_cast<detail::number_type_data*>(data_)} : number_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline pointer_type any_type::as_pointer() const noexcept {
|
inline pointer_type any_type::as_pointer() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<pointer_type>();
|
||||||
return is_pointer() ? pointer_type{static_cast<detail::pointer_type_data*>(data_)} : pointer_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline reference_type any_type::as_reference() const noexcept {
|
inline reference_type any_type::as_reference() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<reference_type>();
|
||||||
return is_reference() ? reference_type{static_cast<detail::reference_type_data*>(data_)} : reference_type{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void_type any_type::as_void() const noexcept {
|
inline void_type any_type::as_void() const noexcept {
|
||||||
// NOLINTNEXTLINE(*-static-cast-downcast)
|
return as<void_type>();
|
||||||
return is_void() ? void_type{static_cast<detail::void_type_data*>(data_)} : void_type{};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user