Преглед на файлове

*: entt::popcount -> std::popcount

skypjack преди 3 месеца
родител
ревизия
537ffb48a7
променени са 4 файла, в които са добавени 5 реда и са изтрити 28 реда
  1. 0 12
      src/entt/core/bit.hpp
  2. 2 1
      src/entt/entity/entity.hpp
  3. 3 2
      src/entt/meta/node.hpp
  4. 0 13
      test/entt/core/bit.cpp

+ 0 - 12
src/entt/core/bit.hpp

@@ -8,18 +8,6 @@
 
 namespace entt {
 
-/**
- * @brief Returns the number of set bits in a value (waiting for C++20 and
- * `std::popcount`).
- * @tparam Type Unsigned integer type.
- * @param value A value of unsigned integer type.
- * @return The number of set bits in the value.
- */
-template<typename Type>
-[[nodiscard]] constexpr std::enable_if_t<std::is_unsigned_v<Type>, int> popcount(const Type value) noexcept {
-    return value ? (int(value & 1) + popcount(static_cast<Type>(value >> 1))) : 0;
-}
-
 /**
  * @brief Checks whether a value is a power of two or not (waiting for C++20 and
  * `std::has_single_bit`).

+ 2 - 1
src/entt/entity/entity.hpp

@@ -1,6 +1,7 @@
 #ifndef ENTT_ENTITY_ENTITY_HPP
 #define ENTT_ENTITY_ENTITY_HPP
 
+#include <bit>
 #include <cstddef>
 #include <cstdint>
 #include <type_traits>
@@ -59,7 +60,7 @@ struct entt_traits<std::uint64_t> {
  */
 template<typename Traits>
 class basic_entt_traits {
-    static constexpr auto length = popcount(Traits::entity_mask);
+    static constexpr auto length = std::popcount(Traits::entity_mask);
 
     static_assert(Traits::entity_mask && ((Traits::entity_mask & (Traits::entity_mask + 1)) == 0), "Invalid entity mask");
     static_assert((Traits::version_mask & (Traits::version_mask + 1)) == 0, "Invalid version mask");

+ 3 - 2
src/entt/meta/node.hpp

@@ -2,6 +2,7 @@
 #define ENTT_META_NODE_HPP
 
 #include <array>
+#include <bit>
 #include <cstddef>
 #include <memory>
 #include <type_traits>
@@ -47,14 +48,14 @@ enum class meta_traits : std::uint32_t {
 template<typename Type>
 [[nodiscard]] auto meta_to_user_traits(const meta_traits traits) noexcept {
     static_assert(std::is_enum_v<Type>, "Invalid enum type");
-    constexpr auto shift = popcount(static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
+    constexpr auto shift = std::popcount(static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
     return Type{static_cast<std::underlying_type_t<Type>>(static_cast<std::underlying_type_t<meta_traits>>(traits) >> shift)};
 }
 
 template<typename Type>
 [[nodiscard]] auto user_to_meta_traits(const Type value) noexcept {
     static_assert(std::is_enum_v<Type>, "Invalid enum type");
-    constexpr auto shift = popcount(static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
+    constexpr auto shift = std::popcount(static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits));
     const auto traits = static_cast<std::underlying_type_t<internal::meta_traits>>(static_cast<std::underlying_type_t<Type>>(value));
     ENTT_ASSERT(traits < ((~static_cast<std::underlying_type_t<meta_traits>>(meta_traits::_user_defined_traits)) >> shift), "Invalid traits");
     return meta_traits{traits << shift};

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

@@ -5,19 +5,6 @@
 #include <entt/core/bit.hpp>
 #include "../../common/config.h"
 
-TEST(PopCount, Functionalities) {
-    // constexpr-ness guaranteed
-    constexpr auto zero_popcount = entt::popcount(0u);
-
-    ASSERT_EQ(zero_popcount, 0u);
-    ASSERT_EQ(entt::popcount(1u), 1u);
-    ASSERT_EQ(entt::popcount(2u), 1u);
-    ASSERT_EQ(entt::popcount(3u), 2u);
-    ASSERT_EQ(entt::popcount(7u), 3u);
-    ASSERT_EQ(entt::popcount(128u), 1u);
-    ASSERT_EQ(entt::popcount(201u), 4u);
-}
-
 TEST(HasSingleBit, Functionalities) {
     // constexpr-ness guaranteed
     constexpr auto zero_is_power_of_two = entt::has_single_bit(0u);