Przeglądaj źródła

*: entt::has_single_bit -> std::has_single_bit

skypjack 3 miesięcy temu
rodzic
commit
760b2aaccf
2 zmienionych plików z 2 dodań i 26 usunięć
  1. 2 13
      src/entt/core/bit.hpp
  2. 0 13
      test/entt/core/bit.cpp

+ 2 - 13
src/entt/core/bit.hpp

@@ -1,6 +1,7 @@
 #ifndef ENTT_CORE_BIT_HPP
 #define ENTT_CORE_BIT_HPP
 
+#include <bit>
 #include <cstddef>
 #include <limits>
 #include <type_traits>
@@ -8,18 +9,6 @@
 
 namespace entt {
 
-/**
- * @brief Checks whether a value is a power of two or not (waiting for C++20 and
- * `std::has_single_bit`).
- * @tparam Type Unsigned integer type.
- * @param value A value of unsigned integer type.
- * @return True if the value is a power of two, false otherwise.
- */
-template<typename Type>
-[[nodiscard]] constexpr std::enable_if_t<std::is_unsigned_v<Type>, bool> has_single_bit(const Type value) noexcept {
-    return value && ((value & (value - 1)) == 0);
-}
-
 /**
  * @brief Computes the smallest power of two greater than or equal to a value
  * (waiting for C++20 and `std::bit_ceil`).
@@ -49,7 +38,7 @@ template<typename Type>
  */
 template<typename Type>
 [[nodiscard]] constexpr std::enable_if_t<std::is_unsigned_v<Type>, Type> fast_mod(const Type value, const std::size_t mod) noexcept {
-    ENTT_ASSERT_CONSTEXPR(has_single_bit(mod), "Value must be a power of two");
+    ENTT_ASSERT_CONSTEXPR(std::has_single_bit(mod), "Value must be a power of two");
     return static_cast<Type>(value & (mod - 1u));
 }
 

+ 0 - 13
test/entt/core/bit.cpp

@@ -5,19 +5,6 @@
 #include <entt/core/bit.hpp>
 #include "../../common/config.h"
 
-TEST(HasSingleBit, Functionalities) {
-    // constexpr-ness guaranteed
-    constexpr auto zero_is_power_of_two = entt::has_single_bit(0u);
-
-    ASSERT_FALSE(zero_is_power_of_two);
-    ASSERT_TRUE(entt::has_single_bit(1u));
-    ASSERT_TRUE(entt::has_single_bit(2u));
-    ASSERT_TRUE(entt::has_single_bit(4u));
-    ASSERT_FALSE(entt::has_single_bit(7u));
-    ASSERT_TRUE(entt::has_single_bit(128u));
-    ASSERT_FALSE(entt::has_single_bit(200u));
-}
-
 TEST(NextPowerOfTwo, Functionalities) {
     // constexpr-ness guaranteed
     constexpr auto next_power_of_two_of_zero = entt::next_power_of_two(0u);