Jelajahi Sumber

config: reintroduce ENTT_CONSTEVAL to make consteval easier for older compilers

skypjack 2 bulan lalu
induk
melakukan
8dd00aea29

+ 12 - 0
src/entt/config/config.h

@@ -15,6 +15,18 @@
 #    define ENTT_CATCH if(false)
 #endif
 
+#if __has_include(<version>)
+#    include <version>
+#
+#    if defined(__cpp_consteval)
+#        define ENTT_CONSTEVAL consteval
+#    endif
+#endif
+
+#ifndef ENTT_CONSTEVAL
+#    define ENTT_CONSTEVAL constexpr
+#endif
+
 #ifdef ENTT_USE_ATOMIC
 #    include <atomic>
 #    define ENTT_MAYBE_ATOMIC(Type) std::atomic<Type>

+ 4 - 4
src/entt/core/hashed_string.hpp

@@ -93,7 +93,7 @@ public:
      */
     template<std::size_t N>
     // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
-    [[nodiscard]] static consteval hash_type value(const value_type (&str)[N]) noexcept {
+    [[nodiscard]] static ENTT_CONSTEVAL hash_type value(const value_type (&str)[N]) noexcept {
         return basic_hashed_string{str};
     }
 
@@ -132,7 +132,7 @@ public:
      */
     template<std::size_t N>
     // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
-    consteval basic_hashed_string(const value_type (&str)[N]) noexcept
+    ENTT_CONSTEVAL basic_hashed_string(const value_type (&str)[N]) noexcept
         // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
         : base_type{str} {
         for(; str[base_type::length]; ++base_type::length) {
@@ -297,7 +297,7 @@ inline namespace literals {
  * @param str The literal without its suffix.
  * @return A properly initialized hashed string.
  */
-[[nodiscard]] consteval hashed_string operator""_hs(const char *str, std::size_t) noexcept {
+[[nodiscard]] ENTT_CONSTEVAL hashed_string operator""_hs(const char *str, std::size_t) noexcept {
     return hashed_string{str};
 }
 
@@ -306,7 +306,7 @@ inline namespace literals {
  * @param str The literal without its suffix.
  * @return A properly initialized hashed wstring.
  */
-[[nodiscard]] consteval hashed_wstring operator""_hws(const wchar_t *str, std::size_t) noexcept {
+[[nodiscard]] ENTT_CONSTEVAL hashed_wstring operator""_hws(const wchar_t *str, std::size_t) noexcept {
     return hashed_wstring{str};
 }
 

+ 1 - 1
src/entt/core/ident.hpp

@@ -16,7 +16,7 @@ namespace entt {
 template<typename... Type>
 class ident {
     template<typename Curr, std::size_t... Index>
-    [[nodiscard]] static consteval id_type get(std::index_sequence<Index...>) noexcept {
+    [[nodiscard]] static ENTT_CONSTEVAL id_type get(std::index_sequence<Index...>) noexcept {
         static_assert((std::is_same_v<Curr, Type> || ...), "Invalid type");
         return (0 + ... + (std::is_same_v<Curr, type_list_element_t<Index, type_list<std::decay_t<Type>...>>> ? id_type{Index} : id_type{}));
     }

+ 2 - 2
src/entt/core/type_info.hpp

@@ -42,7 +42,7 @@ template<typename Type>
 }
 
 template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
-[[nodiscard]] consteval std::string_view type_name(int) noexcept {
+[[nodiscard]] ENTT_CONSTEVAL std::string_view type_name(int) noexcept {
     constexpr auto value = stripped_type_name<Type>();
     return value;
 }
@@ -54,7 +54,7 @@ template<typename Type>
 }
 
 template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
-[[nodiscard]] consteval id_type type_hash(int) noexcept {
+[[nodiscard]] ENTT_CONSTEVAL id_type type_hash(int) noexcept {
     constexpr auto stripped = stripped_type_name<Type>();
     constexpr auto value = hashed_string::value(stripped.data(), stripped.size());
     return value;

+ 12 - 12
src/entt/core/type_traits.hpp

@@ -186,7 +186,7 @@ inline constexpr std::size_t type_list_index_v = type_list_index<Type, List>::va
  * @return A type list composed by the types of both the type lists.
  */
 template<typename... Type, typename... Other>
-consteval type_list<Type..., Other...> operator+(type_list<Type...>, type_list<Other...>) {
+ENTT_CONSTEVAL type_list<Type..., Other...> operator+(type_list<Type...>, type_list<Other...>) {
     return {};
 }
 
@@ -451,7 +451,7 @@ inline constexpr std::size_t value_list_index_v = value_list_index<Value, List>:
  * @return A value list composed by the values of both the value lists.
  */
 template<auto... Value, auto... Other>
-consteval value_list<Value..., Other...> operator+(value_list<Value...>, value_list<Other...>) {
+ENTT_CONSTEVAL value_list<Value..., Other...> operator+(value_list<Value...>, value_list<Other...>) {
     return {};
 }
 
@@ -731,25 +731,25 @@ template<typename Type>
 struct has_value_type<Type, std::void_t<typename Type::value_type>>: std::true_type {};
 
 template<typename>
-[[nodiscard]] consteval bool dispatch_is_equality_comparable();
+[[nodiscard]] ENTT_CONSTEVAL bool dispatch_is_equality_comparable();
 
 template<typename Type, std::size_t... Index>
-[[nodiscard]] consteval bool unpack_maybe_equality_comparable(std::index_sequence<Index...>) {
+[[nodiscard]] ENTT_CONSTEVAL bool unpack_maybe_equality_comparable(std::index_sequence<Index...>) {
     return (dispatch_is_equality_comparable<std::tuple_element_t<Index, Type>>() && ...);
 }
 
 template<typename>
-[[nodiscard]] consteval bool maybe_equality_comparable(char) {
+[[nodiscard]] ENTT_CONSTEVAL bool maybe_equality_comparable(char) {
     return false;
 }
 
 template<typename Type>
-[[nodiscard]] consteval auto maybe_equality_comparable(int) -> decltype(std::declval<Type>() == std::declval<Type>()) {
+[[nodiscard]] ENTT_CONSTEVAL auto maybe_equality_comparable(int) -> decltype(std::declval<Type>() == std::declval<Type>()) {
     return true;
 }
 
 template<typename Type>
-[[nodiscard]] consteval bool dispatch_is_equality_comparable() {
+[[nodiscard]] ENTT_CONSTEVAL bool dispatch_is_equality_comparable() {
     // NOLINTBEGIN(modernize-use-transparent-functors)
     if constexpr(std::is_array_v<Type>) {
         return false;
@@ -856,19 +856,19 @@ using member_class_t = member_class<Member>::type;
 template<std::size_t Index, typename Candidate>
 class nth_argument {
     template<typename Ret, typename... Args>
-    static consteval type_list<Args...> pick_up(Ret (*)(Args...));
+    static ENTT_CONSTEVAL type_list<Args...> pick_up(Ret (*)(Args...));
 
     template<typename Ret, typename Class, typename... Args>
-    static consteval type_list<Args...> pick_up(Ret (Class ::*)(Args...));
+    static ENTT_CONSTEVAL type_list<Args...> pick_up(Ret (Class ::*)(Args...));
 
     template<typename Ret, typename Class, typename... Args>
-    static consteval type_list<Args...> pick_up(Ret (Class ::*)(Args...) const);
+    static ENTT_CONSTEVAL type_list<Args...> pick_up(Ret (Class ::*)(Args...) const);
 
     template<typename Type, typename Class>
-    static consteval type_list<Type> pick_up(Type Class ::*);
+    static ENTT_CONSTEVAL type_list<Type> pick_up(Type Class ::*);
 
     template<typename Type>
-    static consteval decltype(pick_up(&Type::operator())) pick_up(Type &&);
+    static ENTT_CONSTEVAL decltype(pick_up(&Type::operator())) pick_up(Type &&);
 
 public:
     /*! @brief N-th argument of the _callable_ type. */

+ 3 - 3
src/entt/entity/fwd.hpp

@@ -139,7 +139,7 @@ using const_runtime_view = basic_runtime_view<const sparse_set>;
 template<typename... Type>
 struct exclude_t final: type_list<Type...> {
     /*! @brief Default constructor. */
-    explicit consteval exclude_t() = default;
+    explicit ENTT_CONSTEVAL exclude_t() = default;
 };
 
 /**
@@ -156,7 +156,7 @@ inline constexpr exclude_t<Type...> exclude{};
 template<typename... Type>
 struct get_t final: type_list<Type...> {
     /*! @brief Default constructor. */
-    explicit consteval get_t() = default;
+    explicit ENTT_CONSTEVAL get_t() = default;
 };
 
 /**
@@ -173,7 +173,7 @@ inline constexpr get_t<Type...> get{};
 template<typename... Type>
 struct owned_t final: type_list<Type...> {
     /*! @brief Default constructor. */
-    explicit consteval owned_t() = default;
+    explicit ENTT_CONSTEVAL owned_t() = default;
 };
 
 /**

+ 5 - 5
src/entt/meta/utility.hpp

@@ -124,19 +124,19 @@ struct meta_function_descriptor<Type, Ret (*)()>
 template<typename Type, typename Candidate>
 class meta_function_helper {
     template<typename Ret, typename... Args, typename Class>
-    static consteval meta_function_descriptor<Type, Ret (Class::*)(Args...) const> get_rid_of_noexcept(Ret (Class::*)(Args...) const);
+    static meta_function_descriptor<Type, Ret (Class::*)(Args...) const> get_rid_of_noexcept(Ret (Class::*)(Args...) const);
 
     template<typename Ret, typename... Args, typename Class>
-    static consteval meta_function_descriptor<Type, Ret (Class::*)(Args...)> get_rid_of_noexcept(Ret (Class::*)(Args...));
+    static meta_function_descriptor<Type, Ret (Class::*)(Args...)> get_rid_of_noexcept(Ret (Class::*)(Args...));
 
     template<typename Ret, typename Class, typename = std::enable_if_t<std::is_member_object_pointer_v<Ret Class::*>>>
-    static consteval meta_function_descriptor<Type, Ret Class::*> get_rid_of_noexcept(Ret Class::*);
+    static meta_function_descriptor<Type, Ret Class::*> get_rid_of_noexcept(Ret Class::*);
 
     template<typename Ret, typename... Args>
-    static consteval meta_function_descriptor<Type, Ret (*)(Args...)> get_rid_of_noexcept(Ret (*)(Args...));
+    static meta_function_descriptor<Type, Ret (*)(Args...)> get_rid_of_noexcept(Ret (*)(Args...));
 
     template<typename Class>
-    static consteval meta_function_descriptor<Class, decltype(&Class::operator())> get_rid_of_noexcept(Class);
+    static meta_function_descriptor<Class, decltype(&Class::operator())> get_rid_of_noexcept(Class);
 
 public:
     /*! @brief The meta function descriptor of the given function. */

+ 1 - 1
src/entt/poly/poly.hpp

@@ -68,7 +68,7 @@ class poly_vtable {
         -> decltype(std::make_tuple(vtable_entry(Candidate)...));
 
     template<typename... Func>
-    [[nodiscard]] static consteval auto make_vtable(type_list<Func...>) noexcept {
+    [[nodiscard]] static ENTT_CONSTEVAL auto make_vtable(type_list<Func...>) noexcept {
         if constexpr(sizeof...(Func) == 0u) {
             return decltype(make_vtable(typename Concept::template impl<inspector>{})){};
         } else if constexpr((std::is_function_v<Func> && ...)) {

+ 6 - 6
src/entt/signal/delegate.hpp

@@ -16,25 +16,25 @@ namespace entt {
 namespace internal {
 
 template<typename Ret, typename... Args>
-consteval auto function_pointer(Ret (*)(Args...)) -> Ret (*)(Args...);
+auto function_pointer(Ret (*)(Args...)) -> Ret (*)(Args...);
 
 template<typename Ret, typename Type, typename... Args, typename Other>
-consteval auto function_pointer(Ret (*)(Type, Args...), Other &&) -> Ret (*)(Args...);
+auto function_pointer(Ret (*)(Type, Args...), Other &&) -> Ret (*)(Args...);
 
 template<typename Class, typename Ret, typename... Args, typename... Other>
-consteval auto function_pointer(Ret (Class::*)(Args...), Other &&...) -> Ret (*)(Args...);
+auto function_pointer(Ret (Class::*)(Args...), Other &&...) -> Ret (*)(Args...);
 
 template<typename Class, typename Ret, typename... Args, typename... Other>
-consteval auto function_pointer(Ret (Class::*)(Args...) const, Other &&...) -> Ret (*)(Args...);
+auto function_pointer(Ret (Class::*)(Args...) const, Other &&...) -> Ret (*)(Args...);
 
 template<typename Class, typename Type, typename... Other, typename = std::enable_if_t<std::is_member_object_pointer_v<Type Class::*>>>
-consteval auto function_pointer(Type Class::*, Other &&...) -> Type (*)();
+auto function_pointer(Type Class::*, Other &&...) -> Type (*)();
 
 template<typename... Type>
 using function_pointer_t = decltype(function_pointer(std::declval<Type>()...));
 
 template<typename... Class, typename Ret, typename... Args>
-[[nodiscard]] consteval auto index_sequence_for(Ret (*)(Args...)) {
+[[nodiscard]] ENTT_CONSTEVAL auto index_sequence_for(Ret (*)(Args...)) {
     return std::index_sequence_for<Class..., Args...>{};
 }
 

+ 1 - 1
test/entt/core/type_info.cpp

@@ -7,7 +7,7 @@
 
 template<>
 struct entt::type_name<float> final {
-    [[nodiscard]] static consteval std::string_view value() noexcept {
+    [[nodiscard]] static ENTT_CONSTEVAL std::string_view value() noexcept {
         return std::string_view{""};
     }
 };

+ 1 - 1
test/lib/meta/plugin_std/userdata.h

@@ -12,7 +12,7 @@
 #define ASSIGN_TYPE_ID(clazz) \
     template<> \
     struct entt::type_hash<clazz> { \
-        static constexpr entt::id_type value() noexcept { \
+        static ENTT_CONSTEVAL entt::id_type value() noexcept { \
             return entt::basic_hashed_string<std::remove_const_t<std::remove_pointer_t<std::decay_t<decltype(#clazz)>>>>{#clazz}; \
         } \
     }