1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/bit/rotate.hpp
2013-03-22 14:24:19 +09:00

35 lines
736 B
C++

#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
//
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<T>::value,
T
>::type
left_rotate(T x, std::size_t n) {
return (x << n) ^ (x >> (sizeof(T) * CHAR_BIT - n));
}
//
// right_rotate
//
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
std::is_integral<T>::value,
T
>::type
right_rotate(T x, std::size_t n) {
return (x >> n) ^ (x << (sizeof(T) * CHAR_BIT - n));
}
} // namespace sprout
#endif // #ifndef SPROUT_BIT_ROTATE_HPP