memory:
* added utility class is_power_of_two * added variable template is_power_of_two_v
This commit is contained in:
@@ -73,6 +73,22 @@ constexpr void propagate_on_container_swap(Allocator &lhs, Allocator &rhs) ENTT_
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Utility class to check whether a value is a power of two or not.
|
||||
* @tparam Value A value that may or may not be a power of two.
|
||||
*/
|
||||
template<std::size_t Value>
|
||||
using is_power_of_two = std::bool_constant<Value && ((Value & (Value - 1)) == 0)>;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Helper variable template.
|
||||
* @tparam Value A value that may or may not be a power of two.
|
||||
*/
|
||||
template<std::size_t Value>
|
||||
inline constexpr bool is_power_of_two_v = is_power_of_two<Value>::value;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,3 +31,13 @@ TEST(Memory, PoccaPocmaAndPocs) {
|
||||
entt::propagate_on_container_move_assignment(lhs, rhs);
|
||||
entt::propagate_on_container_swap(lhs, rhs);
|
||||
}
|
||||
|
||||
TEST(Memory, IsPowerOfTwo) {
|
||||
ASSERT_FALSE(entt::is_power_of_two_v<0u>);
|
||||
ASSERT_TRUE(entt::is_power_of_two_v<1u>);
|
||||
ASSERT_TRUE(entt::is_power_of_two_v<2u>);
|
||||
ASSERT_TRUE(entt::is_power_of_two_v<4u>);
|
||||
ASSERT_FALSE(entt::is_power_of_two_v<7u>);
|
||||
ASSERT_TRUE(entt::is_power_of_two_v<128u>);
|
||||
ASSERT_FALSE(entt::is_power_of_two_v<200u>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user