Array.h 830 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef ANKI_UTIL_ARRAY_H
  2. #define ANKI_UTIL_ARRAY_H
  3. #include "anki/util/Assert.h"
  4. #include "anki/util/StdTypes.h"
  5. namespace anki {
  6. /// @addtogroup util
  7. /// @{
  8. /// Array
  9. template<typename T, U N>
  10. struct Array
  11. {
  12. typedef T Value;
  13. typedef Value* Iterator;
  14. typedef const Value* ConstIterator;
  15. typedef Value& Reference;
  16. typedef const Value& ConstReference;
  17. Value data[N];
  18. Reference operator[](U n)
  19. {
  20. ANKI_ASSERT(n < N);
  21. return data[n];
  22. }
  23. ConstReference operator[](U n) const
  24. {
  25. ANKI_ASSERT(n < N);
  26. return data[n];
  27. }
  28. Iterator begin()
  29. {
  30. return &data[0];
  31. }
  32. ConstIterator begin() const
  33. {
  34. return &data[0];
  35. }
  36. Iterator end()
  37. {
  38. return &data[0] + N;
  39. }
  40. ConstIterator end() const
  41. {
  42. return &data[0] + N;
  43. }
  44. static constexpr U getSize()
  45. {
  46. return N;
  47. }
  48. };
  49. /// @}
  50. } // end namespace anki
  51. #endif