1
0
Эх сурвалжийг харах

meta_factory: prepare to support void types

skypjack 1 сар өмнө
parent
commit
ac18664c28

+ 7 - 0
src/entt/meta/factory.hpp

@@ -210,6 +210,8 @@ public:
     template<typename Base>
     requires stl::derived_from<element_type, Base>
     meta_factory base() noexcept {
+        static_assert(!std::is_void_v<element_type>, "Feature not supported by void type");
+
         if constexpr(!stl::same_as<element_type, Base>) {
             auto *const op = +[](const void *instance) noexcept { return static_cast<const void *>(static_cast<const Base *>(static_cast<const element_type *>(instance))); };
 
@@ -237,6 +239,7 @@ public:
      */
     template<auto Candidate>
     auto conv() noexcept {
+        static_assert(!std::is_void_v<element_type>, "Feature not supported by void type");
         using conv_type = stl::remove_cvref_t<stl::invoke_result_t<decltype(Candidate), element_type &>>;
         auto *const op = +[](const meta_ctx &area, const void *instance) { return forward_as_meta(area, stl::invoke(Candidate, *static_cast<const element_type *>(instance))); };
 
@@ -259,6 +262,7 @@ public:
      */
     template<typename To>
     meta_factory conv() noexcept {
+        static_assert(!std::is_void_v<element_type>, "Feature not supported by void type");
         using conv_type = stl::remove_cvref_t<To>;
         auto *const op = +[](const meta_ctx &area, const void *instance) { return forward_as_meta(area, static_cast<To>(*static_cast<const element_type *>(instance))); };
 
@@ -285,6 +289,7 @@ public:
      */
     template<auto Candidate, typename Policy = as_value_t>
     meta_factory ctor() noexcept {
+        static_assert(!std::is_void_v<element_type>, "Feature not supported by void type");
         using descriptor = meta_function_helper_t<element_type, decltype(Candidate)>;
         static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
         static_assert(stl::is_same_v<stl::remove_cvref_t<typename descriptor::return_type>, element_type>, "The function doesn't return an object of the required type");
@@ -311,6 +316,8 @@ public:
      */
     template<typename... Args>
     meta_factory ctor() noexcept {
+        static_assert(!std::is_void_v<element_type>, "Feature not supported by void type");
+
         // default constructor is already implicitly generated, no need for redundancy
         if constexpr(sizeof...(Args) != 0u) {
             using descriptor = meta_function_helper_t<element_type, element_type (*)(Args...)>;