|
|
@@ -11,6 +11,42 @@
|
|
|
|
|
|
namespace entt {
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Checks whether a value is a power of two or not.
|
|
|
+ * @param value A value that may or may not be a power of two.
|
|
|
+ * @return True if the value is a power of two, false otherwise.
|
|
|
+ */
|
|
|
+[[nodiscard]] inline bool is_power_of_two(const std::size_t value) noexcept {
|
|
|
+ return value && ((value & (value - 1)) == 0);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Computes the smallest power of two greater than or equal to a value.
|
|
|
+ * @param value The value to use.
|
|
|
+ * @return The smallest power of two greater than or equal to the given value.
|
|
|
+ */
|
|
|
+[[nodiscard]] inline std::size_t next_power_of_two(const std::size_t value) noexcept {
|
|
|
+ ENTT_ASSERT(value < (std::size_t{1u} << (std::numeric_limits<std::size_t>::digits - 1)), "Numeric limits exceeded");
|
|
|
+ std::size_t curr = value - (value != 0u);
|
|
|
+
|
|
|
+ for(int next = 1; next < std::numeric_limits<std::size_t>::digits; next = next * 2) {
|
|
|
+ curr |= curr >> next;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ++curr;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Fast module utility function (powers of two only).
|
|
|
+ * @param value A value for which to calculate the modulus.
|
|
|
+ * @param mod _Modulus_, it must be a power of two.
|
|
|
+ * @return The common remainder.
|
|
|
+ */
|
|
|
+[[nodiscard]] inline std::size_t fast_mod(const std::size_t value, const std::size_t mod) noexcept {
|
|
|
+ ENTT_ASSERT(is_power_of_two(mod), "Value must be a power of two");
|
|
|
+ return value & (mod - 1u);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief Unwraps fancy pointers, does nothing otherwise (waiting for C++20).
|
|
|
* @tparam Type Pointer type.
|
|
|
@@ -68,42 +104,6 @@ constexpr void propagate_on_container_swap([[maybe_unused]] Allocator &lhs, [[ma
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * @brief Checks whether a value is a power of two or not.
|
|
|
- * @param value A value that may or may not be a power of two.
|
|
|
- * @return True if the value is a power of two, false otherwise.
|
|
|
- */
|
|
|
-[[nodiscard]] inline constexpr bool is_power_of_two(const std::size_t value) noexcept {
|
|
|
- return value && ((value & (value - 1)) == 0);
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * @brief Computes the smallest power of two greater than or equal to a value.
|
|
|
- * @param value The value to use.
|
|
|
- * @return The smallest power of two greater than or equal to the given value.
|
|
|
- */
|
|
|
-[[nodiscard]] inline constexpr std::size_t next_power_of_two(const std::size_t value) noexcept {
|
|
|
- ENTT_ASSERT(value < (std::size_t{1u} << (std::numeric_limits<std::size_t>::digits - 1)), "Numeric limits exceeded");
|
|
|
- std::size_t curr = value - (value != 0u);
|
|
|
-
|
|
|
- for(int next = 1; next < std::numeric_limits<std::size_t>::digits; next = next * 2) {
|
|
|
- curr |= curr >> next;
|
|
|
- }
|
|
|
-
|
|
|
- return ++curr;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * @brief Fast module utility function (powers of two only).
|
|
|
- * @param value A value for which to calculate the modulus.
|
|
|
- * @param mod _Modulus_, it must be a power of two.
|
|
|
- * @return The common remainder.
|
|
|
- */
|
|
|
-[[nodiscard]] inline constexpr std::size_t fast_mod(const std::size_t value, const std::size_t mod) noexcept {
|
|
|
- ENTT_ASSERT(is_power_of_two(mod), "Value must be a power of two");
|
|
|
- return value & (mod - 1u);
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* @brief Deleter for allocator-aware unique pointers (waiting for C++20).
|
|
|
* @tparam Args Types of arguments to use to construct the object.
|