1 #ifndef ENTT_CORE_MEMORY_HPP
2 #define ENTT_CORE_MEMORY_HPP
9 #include "../config/config.h"
19 template<
typename Type>
20 [[nodiscard]] constexpr
auto to_address(Type &&ptr) ENTT_NOEXCEPT {
21 if constexpr(std::is_pointer_v<std::remove_const_t<std::remove_reference_t<Type>>>) {
24 return to_address(std::forward<Type>(ptr).operator->());
34 template<
typename Allocator>
36 if constexpr(std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value) {
47 template<
typename Allocator>
49 if constexpr(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value) {
60 template<
typename Allocator>
62 ENTT_ASSERT(std::allocator_traits<Allocator>::propagate_on_container_swap::value || lhs == rhs,
"Cannot swap the containers");
64 if constexpr(std::allocator_traits<Allocator>::propagate_on_container_swap::value) {
75 [[nodiscard]]
inline constexpr
bool is_power_of_two(
const std::size_t value) ENTT_NOEXCEPT {
76 return value && ((value & (value - 1)) == 0);
84 [[nodiscard]]
inline constexpr std::size_t
next_power_of_two(
const std::size_t value) ENTT_NOEXCEPT {
85 ENTT_ASSERT(value < (std::size_t{1u} << (std::numeric_limits<std::size_t>::digits - 1)),
"Numeric limits exceeded");
86 std::size_t curr = value - (value != 0u);
88 for(
int next = 1; next < std::numeric_limits<std::size_t>::digits; next = next * 2) {
101 [[nodiscard]]
inline constexpr std::size_t
fast_mod(
const std::size_t value,
const std::size_t mod) ENTT_NOEXCEPT {
103 return value & (mod - 1u);
constexpr void propagate_on_container_move_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs)
Utility function to design allocation-aware containers.
constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs)
Utility function to design allocation-aware containers.
constexpr std::size_t fast_mod(const std::size_t value, const std::size_t mod)
Fast module utility function (powers of two only).
constexpr bool is_power_of_two(const std::size_t value)
Checks whether a value is a power of two or not.
constexpr std::size_t next_power_of_two(const std::size_t value)
Computes the smallest power of two greater than or equal to a value.
constexpr auto to_address(Type &&ptr)
Unwraps fancy pointers, does nothing otherwise (waiting for C++20).
constexpr void propagate_on_container_copy_assignment([[maybe_unused]] Allocator &lhs, [[maybe_unused]] Allocator &rhs)
Utility function to design allocation-aware containers.
void swap(compressed_pair< First, Second > &lhs, compressed_pair< First, Second > &rhs)
Swaps two compressed pair objects.