24 #ifndef GUL14_BIT_MANIP_H_
25 #define GUL14_BIT_MANIP_H_
28 #include <type_traits>
55 std::is_integral<T>::value
56 and not std::is_same<std::decay_t<T>,
bool>::value,
82 template <
typename T =
unsigned,
typename ReturnT = BitFunctionReturnType<T>>
83 auto constexpr
inline bit_set(
unsigned bit) noexcept -> ReturnT {
84 assert(bit <
sizeof(T) * 8);
85 return static_cast<ReturnT
>(std::make_unsigned_t<T>{1u} << bit);
108 template <
typename T,
typename ReturnT = BitFunctionReturnType<T>>
109 auto constexpr
inline bit_set(T previous,
unsigned bit) noexcept -> ReturnT {
110 return previous | bit_set<T>(bit);
133 template <
typename T,
typename ReturnT = BitFunctionReturnType<T>>
134 auto constexpr
inline bit_reset(T previous,
unsigned bit) noexcept -> ReturnT {
135 return static_cast<ReturnT
>(previous & ~bit_set<T>(bit));
160 template <
typename T,
typename ReturnT = BitFunctionReturnType<T>>
161 auto constexpr
inline bit_flip(T previous,
unsigned bit) noexcept -> ReturnT {
162 return previous ^ bit_set<T>(bit);
185 template <
typename T>
186 bool constexpr
inline bit_test(T bits,
unsigned bit) noexcept {
187 return bits & bit_set<T>(bit);
constexpr auto bit_set(unsigned bit) noexcept -> ReturnT
Set a bit in an integral type.
Definition: bit_manip.h:83
constexpr auto bit_flip(T previous, unsigned bit) noexcept -> ReturnT
Flip a bit in an integral value.
Definition: bit_manip.h:161
constexpr bool bit_test(T bits, unsigned bit) noexcept
Test a bit in an integral value.
Definition: bit_manip.h:186
constexpr auto bit_reset(T previous, unsigned bit) noexcept -> ReturnT
Reset a bit in an integral value.
Definition: bit_manip.h:134
std::enable_if_t< std::is_integral< T >::value and not std::is_same< std::decay_t< T >, bool >::value, std::decay_t< T > > BitFunctionReturnType
Return type of the bit manipulation functions.
Definition: bit_manip.h:58
Definition of macros used internally by GUL.
Namespace gul14 contains all functions and classes of the General Utility Library.
Definition: doxygen.h:26