diff options
Diffstat (limited to 'chilbert/Operations.hpp')
-rw-r--r-- | chilbert/Operations.hpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/chilbert/Operations.hpp b/chilbert/Operations.hpp index c50136a..578daaf 100644 --- a/chilbert/Operations.hpp +++ b/chilbert/Operations.hpp @@ -88,6 +88,18 @@ ffs<unsigned long long>(const unsigned long long field) return __builtin_ffsll(field); } +/// Calculates the Gray Code of `value` in place +template <typename T> +std::enable_if_t<!std::is_integral<T>::value> grayCode(T& value); + +/// Implementation of grayCode for any integral type +template <typename T> +std::enable_if_t<std::is_integral<T>::value> +grayCode(T& value) +{ + value ^= (value >> 1); +} + /// Calculates the inverse Gray Code of `value` in place template <typename T> std::enable_if_t<!std::is_integral<T>::value> grayCodeInv(T& value); |