24template <
class T, T start, T stop>
28 using raw_type = std::underlying_type_t<T>;
41 std::is_signed<raw_type>::value
47 static constexpr stored_type makeEnd()
49 return std::numeric_limits<stored_type>::max();
59 : _current{static_cast<stored_type>(t)}
65 using pointer = std::add_pointer_t<value_type>;
66 using reference = std::add_lvalue_reference_t<value_type>;
70 using const_reference = std::add_lvalue_reference_t<std::add_const_t<value_type>>;
81 std::swap(lhs._current, rhs._current);
96 if (makeEnd() != _current)
98 if (_current <
static_cast<stored_type
>(stop))
104 _current = makeEnd();
124 return *
reinterpret_cast<pointer>(&_current);
136 bool derefable()
const
140 && (_current <= static_cast<stored_type>(std::numeric_limits<raw_type>::max()))
141 && (_current >=
static_cast<stored_type
>(std::numeric_limits<raw_type>::min()))
142 && (_current <=
static_cast<stored_type
>(stop))
143 && (_current >=
static_cast<stored_type
>(start));
147 static_assert(std::is_enum<T>::value,
"Enum expected");
148 static_assert(
static_cast<raw_type
>(stop) >=
static_cast<raw_type
>(start),
"Invalid range");
149 static_assert(
static_cast<raw_type
>(stop) < makeEnd(),
"Past-the-end value impossible");
150 static_assert( ! std::is_floating_point<raw_type>::value,
"Floating points not allowed");
154 stored_type _current = makeEnd();
Definition enumiterator.h:26
const_reference operator->() const
Definition enumiterator.h:92
T value_type
Definition enumiterator.h:64
EnumIterator & operator++()
Definition enumiterator.h:94
bool operator==(EnumIterator rhs) const
Definition enumiterator.h:86
EnumIterator(EnumIterator &&)=default
EnumIterator end() const
Definition enumiterator.h:118
EnumIterator & operator=(EnumIterator &&)=default
friend void swap(EnumIterator &lhs, EnumIterator &rhs)
Definition enumiterator.h:79
EnumIterator(const EnumIterator &)=default
EnumIterator begin() const
Definition enumiterator.h:117
std::ptrdiff_t difference_type
Definition enumiterator.h:63
EnumIterator & operator=(const EnumIterator &)=default
EnumIterator operator++(int) const
Definition enumiterator.h:111
reference operator->()
Definition enumiterator.h:91
reference operator*()
Definition enumiterator.h:120
const_reference operator*() const
Definition enumiterator.h:127
std::add_pointer_t< std::add_const_t< value_type > > const_pointer
Definition enumiterator.h:71
std::add_pointer_t< value_type > pointer
Definition enumiterator.h:65
std::forward_iterator_tag iterator_category
Definition enumiterator.h:67
std::add_lvalue_reference_t< std::add_const_t< value_type > > const_reference
Definition enumiterator.h:70
bool operator!=(EnumIterator rhs) const
Definition enumiterator.h:87
std::add_lvalue_reference_t< value_type > reference
Definition enumiterator.h:66
EnumIterator(T t)
Definition enumiterator.h:58