stellar

UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

utils.hpp (1113B)


0 #ifndef STELLAR_UTILS_CPP_H
1 #define STELLAR_UTILS_CPP_H
3 #include <cstdint>
5 #define C64(constantU64) constantU64##ULL
6 #define C32(constantU64) constantU64##UL
8 typedef uint64_t U64;
9 typedef uint32_t U32;
11 #include <type_traits>
13 template <typename E> constexpr typename std::underlying_type<E>::type to_underlying(E e) noexcept {
14 return static_cast<typename std::underlying_type<E>::type>(e);
15 }
17 template <typename C, C beginVal, C endVal> class Iterator {
18 typedef typename std::underlying_type<C>::type val_t;
19 int val;
21 public:
22 constexpr Iterator(const C &f) : val(static_cast<val_t>(f)) {}
23 constexpr Iterator() : val(static_cast<val_t>(beginVal)) {}
24 constexpr Iterator operator++() {
25 ++val;
26 return *this;
27 }
28 constexpr C operator*() { return static_cast<C>(val); }
29 constexpr Iterator begin() { return *this; }
30 constexpr Iterator end() {
31 // static const Iterator endIter = ++Iterator(endVal);
32 // return endIter;
33 return ++Iterator(endVal);
34 }
35 constexpr bool operator!=(const Iterator &i) { return val != i.val; }
36 };
38 #endif