libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::mpl::count_setbits< Val > Struct Template Reference

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
 

Detailed Description

template<unsigned long long Val>
struct jmmcg::LIBJMMCG_VER_NAMESPACE::mpl::count_setbits< 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.

Member Typedef Documentation

◆ element_type

template<unsigned long long Val>
typedef unsigned long long jmmcg::LIBJMMCG_VER_NAMESPACE::mpl::count_setbits< Val >::element_type

Definition at line 39 of file count_setbits.hpp.

Member Enumeration Documentation

◆ anonymous enum

template<unsigned long long Val>
anonymous enum : element_type
Enumerator
value 

Definition at line 43 of file count_setbits.hpp.

Member Function Documentation

◆ efficiency()

template<unsigned long long Val>
constexpr static float jmmcg::LIBJMMCG_VER_NAMESPACE::mpl::count_setbits< Val >::efficiency ( )
inlinestaticconstexprnoexcept

Definition at line 47 of file count_setbits.hpp.

Member Data Documentation

◆ number

template<unsigned long long Val>
constexpr static element_type jmmcg::LIBJMMCG_VER_NAMESPACE::mpl::count_setbits< Val >::number =Val
staticconstexpr

Definition at line 41 of file count_setbits.hpp.


The documentation for this struct was generated from the following file: