libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
|
Count the number of set bits in the compile-time constant, input number. More...
#include <count_setbits.hpp>
Public Types | |
enum | : element_type { value =(count_setbits<(Val>>1u)>::value+(Val&1u)) } |
typedef unsigned long long | element_type |
Static Public Member Functions | |
constexpr static float | efficiency () noexcept(true) |
Static Public Attributes | |
constexpr static element_type | number =Val |
Count the number of set bits in the compile-time constant, input number.
Because the operator>>() is poorly defined this only works for unsigned types. This is because there may be a sign bit or two's complement representation of the negative number. Then shifting might cause the sign bit to be shifted into the number itself, possibly causing an infinite loop.
Complexity: compile-time: O(n) where n is at most the number of bits used to represent the input type. run-time: O(1) Space: O(1)
Definition at line 38 of file count_setbits.hpp.
typedef unsigned long long jmmcg::LIBJMMCG_VER_NAMESPACE::mpl::count_setbits< Val >::element_type |
Definition at line 39 of file count_setbits.hpp.
anonymous enum : element_type |
Enumerator | |
---|---|
value |
Definition at line 43 of file count_setbits.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 47 of file count_setbits.hpp.
|
staticconstexpr |
Definition at line 41 of file count_setbits.hpp.