ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
iterable_enum.h
Go to the documentation of this file.
1 #pragma once
2 
8 template <typename T> class IterableEnum {
9 public:
13  class Iterator {
14  public:
18  Iterator(int value) : m_value_(value) {}
19 
23  T operator*(void)const { return (T)m_value_; }
24 
28  void operator++(void) { ++m_value_; }
29 
33  bool operator!=(Iterator rhs) { return m_value_ != rhs.m_value_; }
34 
35  private:
36  int m_value_;
37  };
38 };
39 
44 template <typename T>
46  return typename IterableEnum<T>::Iterator((int)T::First);
47 }
48 
53 template <typename T> typename IterableEnum<T>::Iterator end(IterableEnum<T>) {
54  return typename IterableEnum<T>::Iterator(((int)T::Last) + 1);
55 }
T operator*(void) const
Returns underlying iterator value.
Definition: iterable_enum.h:23
IterableEnum< T >::Iterator begin(IterableEnum< T >)
Iterator corresponding to the beginning of the enum.
Definition: iterable_enum.h:45
Iterator for the wrapper class.
Definition: iterable_enum.h:13
IterableEnum< T >::Iterator end(IterableEnum< T >)
Iterator corresponding to the last value of the enum.
Definition: iterable_enum.h:53
Iterable wrapper class for iterating over enums. Only works for enums that are contiguous.
Definition: iterable_enum.h:8
bool operator!=(Iterator rhs)
Compare iterator using underlying value.
Definition: iterable_enum.h:33
Iterator(int value)
Constructor.
Definition: iterable_enum.h:18
void operator++(void)
Increment iterator.
Definition: iterable_enum.h:28