Przeglądaj źródła

stl: std::as_const

skypjack 1 dzień temu
rodzic
commit
80fdab4f21

+ 2 - 2
src/entt/container/dense_map.hpp

@@ -61,7 +61,7 @@ class dense_map_iterator final {
     friend class dense_map_iterator;
 
     static_assert(std::is_pointer_v<It>, "Not a pointer type");
-    using first_type = decltype(std::as_const(stl::declval<It>()->element.first));
+    using first_type = decltype(stl::as_const(stl::declval<It>()->element.first));
     using second_type = decltype((stl::declval<It>()->element.second));
 
 public:
@@ -156,7 +156,7 @@ class dense_map_local_iterator final {
     friend class dense_map_local_iterator;
 
     static_assert(std::is_pointer_v<It>, "Not a pointer type");
-    using first_type = decltype(std::as_const(stl::declval<It>()->element.first));
+    using first_type = decltype(stl::as_const(stl::declval<It>()->element.first));
     using second_type = decltype((stl::declval<It>()->element.second));
 
 public:

+ 7 - 7
src/entt/core/any.hpp

@@ -390,7 +390,7 @@ public:
      * @return An opaque pointer the contained instance, if any.
      */
     [[nodiscard]] void *data() noexcept {
-        return (mode == any_policy::cref) ? nullptr : const_cast<void *>(std::as_const(*this).data());
+        return (mode == any_policy::cref) ? nullptr : const_cast<void *>(stl::as_const(*this).data());
     }
 
     /**
@@ -399,7 +399,7 @@ public:
      * @return An opaque pointer the contained instance, if any.
      */
     [[nodiscard]] void *data(const type_info &req) noexcept {
-        return (mode == any_policy::cref) ? nullptr : const_cast<void *>(std::as_const(*this).data(req));
+        return (mode == any_policy::cref) ? nullptr : const_cast<void *>(stl::as_const(*this).data(req));
     }
 
     /**
@@ -410,9 +410,9 @@ public:
     template<typename Type>
     [[nodiscard]] Type *data() noexcept {
         if constexpr(std::is_const_v<Type>) {
-            return std::as_const(*this).template data<std::remove_const_t<Type>>();
+            return stl::as_const(*this).template data<std::remove_const_t<Type>>();
         } else {
-            return (mode == any_policy::cref) ? nullptr : const_cast<Type *>(std::as_const(*this).template data<std::remove_const_t<Type>>());
+            return (mode == any_policy::cref) ? nullptr : const_cast<Type *>(stl::as_const(*this).template data<std::remove_const_t<Type>>());
         }
     }
 
@@ -445,7 +445,7 @@ public:
     // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
     bool assign(basic_any &&other) {
         if(other && (mode != any_policy::cref) && (underlying_type == other.underlying_type)) {
-            return (other.mode == any_policy::cref) ? (vtable(request::assign, *this, std::as_const(other).data()) != nullptr) : (vtable(request::transfer, *this, other.data()) != nullptr);
+            return (other.mode == any_policy::cref) ? (vtable(request::assign, *this, stl::as_const(other).data()) != nullptr) : (vtable(request::transfer, *this, other.data()) != nullptr);
         }
 
         return false;
@@ -483,7 +483,7 @@ public:
      * @return A wrapper that shares a reference to an unmanaged object.
      */
     [[nodiscard]] basic_any as_ref() noexcept {
-        basic_any other = std::as_const(*this).as_ref();
+        basic_any other = stl::as_const(*this).as_ref();
 
         switch(mode) {
             using enum any_policy;
@@ -584,7 +584,7 @@ template<typename Type, std::size_t Len, std::size_t Align>
 [[nodiscard]] Type *any_cast(basic_any<Len, Align> *data) noexcept {
     if constexpr(std::is_const_v<Type>) {
         // last attempt to make wrappers for const references return their values
-        return any_cast<Type>(&std::as_const(*data));
+        return any_cast<Type>(&stl::as_const(*data));
     } else {
         return data->template data<Type>();
     }

+ 4 - 4
src/entt/entity/registry.hpp

@@ -393,7 +393,7 @@ public:
      * @return A pointer to the storage if it exists, a null pointer otherwise.
      */
     [[nodiscard]] common_type *storage(const id_type id) {
-        return const_cast<common_type *>(std::as_const(*this).storage(id));
+        return const_cast<common_type *>(stl::as_const(*this).storage(id));
     }
 
     /**
@@ -783,7 +783,7 @@ public:
     template<typename Func>
     void erase_if(const entity_type entt, Func func) {
         for(auto [id, cpool]: storage()) {
-            if(cpool.contains(entt) && func(id, std::as_const(cpool))) {
+            if(cpool.contains(entt) && func(id, stl::as_const(cpool))) {
                 cpool.erase(entt);
             }
         }
@@ -909,7 +909,7 @@ public:
     template<typename... Type>
     [[nodiscard]] auto try_get([[maybe_unused]] const entity_type entt) {
         if constexpr(sizeof...(Type) == 1u) {
-            return (const_cast<Type *>(std::as_const(*this).template try_get<Type>(entt)), ...);
+            return (const_cast<Type *>(stl::as_const(*this).template try_get<Type>(entt)), ...);
         } else {
             return stl::make_tuple(try_get<Type>(entt)...);
         }
@@ -1130,7 +1130,7 @@ public:
         auto &cpool = assure<Type>();
 
         if constexpr(std::is_invocable_v<Compare, decltype(cpool.get({})), decltype(cpool.get({}))>) {
-            auto comp = [&cpool, compare = stl::move(compare)](const auto lhs, const auto rhs) { return compare(std::as_const(cpool.get(lhs)), std::as_const(cpool.get(rhs))); };
+            auto comp = [&cpool, compare = stl::move(compare)](const auto lhs, const auto rhs) { return compare(stl::as_const(cpool.get(lhs)), stl::as_const(cpool.get(rhs))); };
             cpool.sort(stl::move(comp), stl::move(algo), stl::forward<Args>(args)...);
         } else {
             cpool.sort(stl::move(compare), stl::move(algo), stl::forward<Args>(args)...);

+ 2 - 2
src/entt/entity/sparse_set.hpp

@@ -533,7 +533,7 @@ public:
         const auto len = sparse.size();
         other.reserve(len);
 
-        for(size_type cnt{}; auto &&elem: std::as_const(packed)) {
+        for(size_type cnt{}; auto &&elem: stl::as_const(packed)) {
             if(elem != tombstone) {
                 if(const auto page = pos_to_page(entity_to_pos(elem)); sparse[page] != nullptr) {
                     if(const auto sz = page + 1u; sz > other.size()) {
@@ -748,7 +748,7 @@ public:
 
     /*! @copydoc value */
     [[nodiscard]] void *value(const entity_type entt) noexcept {
-        return const_cast<void *>(std::as_const(*this).value(entt));
+        return const_cast<void *>(stl::as_const(*this).value(entt));
     }
 
     /**

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

@@ -636,7 +636,7 @@ public:
 
     /*! @copydoc get */
     [[nodiscard]] value_type &get(const entity_type entt) noexcept {
-        return const_cast<value_type &>(std::as_const(*this).get(entt));
+        return const_cast<value_type &>(stl::as_const(*this).get(entt));
     }
 
     /**
@@ -1175,7 +1175,7 @@ public:
      * @return An iterable object to use to _visit_ the storage.
      */
     [[nodiscard]] iterable each() noexcept {
-        return std::as_const(*this).each();
+        return stl::as_const(*this).each();
     }
 
     /*! @copydoc each */
@@ -1193,7 +1193,7 @@ public:
      * @return A reverse iterable object to use to _visit_ the storage.
      */
     [[nodiscard]] reverse_iterable reach() noexcept {
-        return std::as_const(*this).reach();
+        return stl::as_const(*this).reach();
     }
 
     /*! @copydoc reach */

+ 6 - 6
src/entt/meta/meta.hpp

@@ -449,7 +449,7 @@ public:
     /*! @copydoc try_cast */
     template<typename Type>
     [[nodiscard]] Type *try_cast() {
-        return ((storage.policy() == any_policy::cref) && !std::is_const_v<Type>) ? nullptr : const_cast<Type *>(std::as_const(*this).try_cast<std::remove_const_t<Type>>());
+        return ((storage.policy() == any_policy::cref) && !std::is_const_v<Type>) ? nullptr : const_cast<Type *>(stl::as_const(*this).try_cast<std::remove_const_t<Type>>());
     }
 
     /**
@@ -512,7 +512,7 @@ public:
                     for(auto &&curr: from.details->base) {
                         if(auto other = curr.type(internal::meta_context::from(*ctx)).from_void(*ctx, nullptr, curr.cast(storage.data())); curr.id == entt::type_hash<stl::remove_cvref_t<Type>>::value()) {
                             return other;
-                        } else if(auto from_base = std::as_const(other).template allow_cast<Type>(); from_base) {
+                        } else if(auto from_base = stl::as_const(other).template allow_cast<Type>(); from_base) {
                             return from_base;
                         }
                     }
@@ -535,7 +535,7 @@ public:
         } else {
             if(storage.has_value<stl::remove_cvref_t<Type>>()) {
                 return true;
-            } else if(auto other = std::as_const(*this).allow_cast<stl::remove_cvref_t<Type>>(); other) {
+            } else if(auto other = stl::as_const(*this).allow_cast<stl::remove_cvref_t<Type>>(); other) {
                 if(other.storage.owner()) {
                     std::swap(*this, other);
                 }
@@ -1556,7 +1556,7 @@ bool meta_any::set(const id_type id, Type &&value) {
             for(auto &&curr: from.details->base) {
                 if(auto other = curr.type(internal::meta_context::from(*ctx)).from_void(*ctx, nullptr, curr.cast(storage.data())); curr.id == type.info().hash()) {
                     return other;
-                } else if(auto from_base = std::as_const(other).allow_cast(type); from_base) {
+                } else if(auto from_base = stl::as_const(other).allow_cast(type); from_base) {
                     return from_base;
                 }
             }
@@ -1569,7 +1569,7 @@ bool meta_any::set(const id_type id, Type &&value) {
 [[nodiscard]] inline bool meta_any::allow_cast(const meta_type &type) {
     if(storage.has_value(type.info())) {
         return true;
-    } else if(auto other = std::as_const(*this).allow_cast(type); other) {
+    } else if(auto other = stl::as_const(*this).allow_cast(type); other) {
         if(other.storage.owner()) {
             std::swap(*this, other);
         }
@@ -1590,7 +1590,7 @@ inline bool meta_any::assign(const meta_any &other) {
 }
 
 inline bool meta_any::assign(meta_any &&other) {
-    return storage.assign(stl::move(other.storage)) || storage.assign(std::as_const(other).allow_cast(type()).storage);
+    return storage.assign(stl::move(other.storage)) || storage.assign(stl::as_const(other).allow_cast(type()).storage);
 }
 
 [[nodiscard]] inline meta_type meta_data::type() const noexcept {

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

@@ -169,7 +169,7 @@ template<meta_policy Policy = as_value_t, typename Type>
 [[nodiscard]] meta_any meta_dispatch(const meta_ctx &ctx, [[maybe_unused]] Type &&value) {
     if constexpr(stl::is_same_v<Policy, as_cref_t>) {
         static_assert(std::is_lvalue_reference_v<Type>, "Invalid type");
-        return meta_any{ctx, std::in_place_type<const std::remove_reference_t<Type> &>, std::as_const(value)};
+        return meta_any{ctx, std::in_place_type<const std::remove_reference_t<Type> &>, stl::as_const(value)};
     } else if constexpr(stl::is_same_v<Policy, as_ref_t> || (stl::is_same_v<Policy, as_is_t> && std::is_lvalue_reference_v<Type>)) {
         return meta_any{ctx, std::in_place_type<Type>, value};
     } else if constexpr(stl::is_same_v<Policy, as_void_t>) {

+ 1 - 0
src/entt/stl/utility.hpp

@@ -6,6 +6,7 @@
 /*! @cond ENTT_INTERNAL */
 namespace entt::stl {
 
+using std::as_const;
 using std::declval;
 using std::exchange;
 using std::forward;