carb::cpp20::has_single_bit

Defined in carb/cpp20/Bit.h

template<class T, std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, bool> = false>
constexpr bool carb::cpp20::has_single_bit(T val)

Checks if a given value is an integral power of 2.

See

https://en.cppreference.com/w/cpp/numeric/has_single_bit

Template Parameters

T – An unsigned integral type

Parameters

val – An unsigned integral value

Returns

true if val is not zero and has a single bit set (integral power of two); false otherwise.