stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE | |
utils.hpp (1113B)
1 #ifndef STELLAR_UTILS_CPP_H 2 #define STELLAR_UTILS_CPP_H 3 4 #include <cstdint> 5 6 #define C64(constantU64) constantU64##ULL 7 #define C32(constantU64) constantU64##UL 8 9 typedef uint64_t U64; 10 typedef uint32_t U32; 11 12 #include <type_traits> 13 14 template <typename E> constexpr typename std::underlying_type<E>::type to_underlying(E e) noexcept { 15 return static_cast<typename std::underlying_type<E>::type>(e); 16 } 17 18 template <typename C, C beginVal, C endVal> class Iterator { 19 typedef typename std::underlying_type<C>::type val_t; 20 int val; 21 22 public: 23 constexpr Iterator(const C &f) : val(static_cast<val_t>(f)) {} 24 constexpr Iterator() : val(static_cast<val_t>(beginVal)) {} 25 constexpr Iterator operator++() { 26 ++val; 27 return *this; 28 } 29 constexpr C operator*() { return static_cast<C>(val); } 30 constexpr Iterator begin() { return *this; } 31 constexpr Iterator end() { 32 // static const Iterator endIter = ++Iterator(endVal); 33 // return endIter; 34 return ++Iterator(endVal); 35 } 36 constexpr bool operator!=(const Iterator &i) { return val != i.val; } 37 }; 38 39 #endif