Array.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef ANKI_PtrSizeTIL_ARRAY_H
  2. #define ANKI_PtrSizeTIL_ARRAY_H
  3. #include "anki/util/Assert.h"
  4. #include "anki/util/StdTypes.h"
  5. namespace anki {
  6. /// @addtogroup util
  7. /// @{
  8. /// Like std::array but with some additions
  9. template<typename T, PtrSize 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[](const PtrSize n)
  19. {
  20. ANKI_ASSERT(n < N);
  21. return data[n];
  22. }
  23. ConstReference operator[](const PtrSize n) const
  24. {
  25. ANKI_ASSERT(n < N);
  26. return data[n];
  27. }
  28. /// Make it compatible with the C++11 range based for loop
  29. Iterator begin()
  30. {
  31. return &data[0];
  32. }
  33. /// Make it compatible with the C++11 range based for loop
  34. ConstIterator begin() const
  35. {
  36. return &data[0];
  37. }
  38. /// Make it compatible with the C++11 range based for loop
  39. Iterator end()
  40. {
  41. return &data[0] + N;
  42. }
  43. /// Make it compatible with the C++11 range based for loop
  44. ConstIterator end() const
  45. {
  46. return &data[0] + N;
  47. }
  48. static constexpr PtrSize getSize()
  49. {
  50. return N;
  51. }
  52. };
  53. /// @}
  54. } // end namespace anki
  55. #endif