31 template <
unsigned int N>
34 static constexpr unsigned int value = 1U +
log2of<N/2>::value ;
40 static constexpr unsigned int value = 0U ;
43 template <
typename Talign,
typename Tvalue>
45 constexpr Tvalue mask( Tvalue n )
47 return n & (~(Tvalue(0))<<
log2of<
sizeof(Talign)>::value) ;
50 template <
typename Talign,
typename Tvalue>
52 constexpr Tvalue shift( Tvalue n )
54 return n >> log2of<
sizeof(Talign)>::value ;
57 template <
typename Talign,
typename T
char>
58 inline void * align_imp(
const Tchar * p ,
const std::size_t n_in )
60 void * vp =
const_cast<Tchar*
>(p) ;
61 std::size_t n = n_in ;
62 return std::align(
alignof(Talign) ,
sizeof(Talign) , vp , n ) ;
70 inline void *
align(
const char * buffer , std::size_t buffer_size )
72 return AlignImp::align_imp<T>( buffer , buffer_size ) ;
79 inline void *
align(
const unsigned char * buffer , std::size_t buffer_size )
81 return AlignImp::align_imp<T>( buffer , buffer_size ) ;
91 return AlignImp::shift<T>( n ) ;
101 return AlignImp::mask<T>( n ) ;
constexpr std::size_t align_mask(std::size_t n)
Rounds down the number of bytes in a range to give a number of bytes that will hold an exact number o...
constexpr std::size_t align_shift(std::size_t n)
Divides the number of bytes in a range to give the number of whole Ts.
void * align(const char *buffer, std::size_t buffer_size)
Returns a pointer inside the given buffer that is aligned for values of type T.
void * align(const unsigned char *buffer, std::size_t buffer_size)
Returns a pointer inside the given unsigned-char buffer that is aligned for values of type T.
Evaluates the number of bits in the template parameter N.