config: ENTT_USE_STL (mainly for test purposes)

This commit is contained in:
skypjack
2025-12-19 17:47:17 +01:00
parent 5460315b6e
commit 036196bed3
4 changed files with 23 additions and 24 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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);
}