Sfoglia il codice sorgente

config: ENTT_USE_STL (mainly for test purposes)

skypjack 2 mesi fa
parent
commit
036196bed3
4 ha cambiato i file con 23 aggiunte e 24 eliminazioni
  1. 4 0
      src/entt/config/config.h
  2. 16 21
      src/entt/stl/memory.hpp
  3. 1 1
      test/CMakeLists.txt
  4. 2 2
      test/entt/stl/memory.cpp

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

@@ -5,6 +5,10 @@
 
 // NOLINTBEGIN(cppcoreguidelines-macro-usage)
 
+#ifdef ENTT_USE_STL
+#    define ENTT_FORCE_STL
+#endif
+
 #if defined(__cpp_exceptions) && !defined(ENTT_NO_EXCEPTION)
 #    define ENTT_THROW throw
 #    define ENTT_TRY try

+ 16 - 21
src/entt/stl/memory.hpp

@@ -1,15 +1,26 @@
 #ifndef ENTT_STL_MEMORY_HPP
 #define ENTT_STL_MEMORY_HPP
 
-#include <memory>
-#include <type_traits>
-#include <utility>
+#include "../config/config.h"
 
 namespace entt::stl {
 
-/*! @cond TURN_OFF_DOXYGEN */
-namespace internal {
+#ifndef ENTT_FORCE_STL
+#    if __has_include(<version>)
+#        include <version>
+#
+#        if defined(__cpp_lib_to_address)
+#            define ENTT_HAS_TO_ADDRESS
+#            include <memory>
+using std::to_address;
+#        endif
+#    endif
+#endif
 
+#ifndef ENTT_HAS_TO_ADDRESS
+#    include <type_traits>
+#    include <utility>
+#
 template<typename Type>
 [[nodiscard]] constexpr auto to_address(Type &&ptr) noexcept {
     if constexpr(std::is_pointer_v<std::decay_t<Type>>) {
@@ -18,24 +29,8 @@ template<typename Type>
         return to_address(std::forward<Type>(ptr).operator->());
     }
 }
-
-} // namespace internal
-/*! @endcond */
-
-#if __has_include(<version>)
-#    include <version>
-#
-#    if defined(__cpp_lib_to_address)
-#        define ENTT_STL_TO_ADDRESS std::to_address
-#    endif
 #endif
 
-#ifndef ENTT_STL_TO_ADDRESS
-#    define ENTT_STL_TO_ADDRESS internal::to_address
-#endif
-
-using ENTT_STL_TO_ADDRESS;
-
 } // namespace entt::stl
 
 #endif

+ 1 - 1
test/CMakeLists.txt

@@ -304,4 +304,4 @@ SETUP_BASIC_TEST(sigh entt/signal/sigh.cpp)
 
 # Test stl
 
-SETUP_BASIC_TEST(stl_memory entt/stl/memory.cpp)
+SETUP_BASIC_TEST(stl_memory entt/stl/memory.cpp ENTT_USE_STL)

+ 2 - 2
test/entt/stl/memory.cpp

@@ -6,6 +6,6 @@ TEST(ToAddress, Functionalities) {
     const std::shared_ptr<int> shared = std::make_shared<int>();
     auto *plain = &*shared;
 
-    ASSERT_EQ(entt::stl::internal::to_address(shared), plain);
-    ASSERT_EQ(entt::stl::internal::to_address(plain), plain);
+    ASSERT_EQ(entt::stl::to_address(shared), plain);
+    ASSERT_EQ(entt::stl::to_address(plain), plain);
 }