2012-08-08 12:59:47 +00:00
|
|
|
#ifndef SPROUT_BIT_ROTATE_HPP
|
|
|
|
#define SPROUT_BIT_ROTATE_HPP
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <climits>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// left_rotate
|
|
|
|
//
|
2012-12-17 11:10:17 +00:00
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
std::is_integral<T>::value,
|
|
|
|
T
|
|
|
|
>::type
|
2012-08-08 12:59:47 +00:00
|
|
|
left_rotate(T x, std::size_t n) {
|
|
|
|
return (x << n) ^ (x >> (sizeof(T) * CHAR_BIT - n));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// right_rotate
|
|
|
|
//
|
2012-12-17 11:10:17 +00:00
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
std::is_integral<T>::value,
|
|
|
|
T
|
|
|
|
>::type
|
2012-08-08 12:59:47 +00:00
|
|
|
right_rotate(T x, std::size_t n) {
|
|
|
|
return (x >> n) ^ (x << (sizeof(T) * CHAR_BIT - n));
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
2013-03-22 05:24:19 +00:00
|
|
|
#endif // #ifndef SPROUT_BIT_ROTATE_HPP
|