1#ifndef ENTT_CORE_BIT_HPP
2#define ENTT_CORE_BIT_HPP
7#include "../config/config.h"
18template<
typename Type>
19[[
nodiscard]]
constexpr std::enable_if_t<std::is_unsigned_v<Type>,
int>
popcount(
const Type value)
noexcept {
20 return value ? (
int(value & 1) +
popcount(
static_cast<Type
>(value >> 1))) : 0;
30template<
typename Type>
32 return value && ((value & (value - 1)) == 0);
42template<
typename Type>
44 ENTT_ASSERT_CONSTEXPR(value < (Type{1u} << (std::numeric_limits<Type>::digits - 1)),
"Numeric limits exceeded");
45 Type
curr = value - (value != 0
u);
61template<
typename Type>
62[[
nodiscard]]
constexpr std::enable_if_t<std::is_unsigned_v<Type>, Type>
fast_mod(
const Type value,
const std::size_t
mod)
noexcept {
64 return value & (
mod - 1u);
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
constexpr std::enable_if_t< std::is_unsigned_v< Type >, Type > fast_mod(const Type value, const std::size_t mod) noexcept
Fast module utility function (powers of two only).
constexpr std::enable_if_t< std::is_unsigned_v< Type >, bool > has_single_bit(const Type value) noexcept
Checks whether a value is a power of two or not (waiting for C++20 and std::has_single_bit).
constexpr std::enable_if_t< std::is_unsigned_v< Type >, Type > next_power_of_two(const Type value) noexcept
Computes the smallest power of two greater than or equal to a value (waiting for C++20 and std::bit_c...
constexpr std::enable_if_t< std::is_unsigned_v< Type >, int > popcount(const Type value) noexcept
Returns the number of set bits in a value (waiting for C++20 and std::popcount).