Array.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /// @addtogroup containers
  9. /// @{
  10. /// Like std::array but with some additions
  11. template<typename T, PtrSize N>
  12. struct Array
  13. {
  14. typedef T Value;
  15. typedef Value* Iterator;
  16. typedef const Value* ConstIterator;
  17. typedef Value& Reference;
  18. typedef const Value& ConstReference;
  19. Value data[N];
  20. Reference operator[](const PtrSize n)
  21. {
  22. ANKI_ASSERT(n < N);
  23. return data[n];
  24. }
  25. ConstReference operator[](const PtrSize n) const
  26. {
  27. ANKI_ASSERT(n < N);
  28. return data[n];
  29. }
  30. /// Make it compatible with the C++11 range based for loop
  31. Iterator begin()
  32. {
  33. return &data[0];
  34. }
  35. /// Make it compatible with the C++11 range based for loop
  36. ConstIterator begin() const
  37. {
  38. return &data[0];
  39. }
  40. /// Make it compatible with the C++11 range based for loop
  41. Iterator end()
  42. {
  43. return &data[0] + N;
  44. }
  45. /// Make it compatible with the C++11 range based for loop
  46. ConstIterator end() const
  47. {
  48. return &data[0] + N;
  49. }
  50. static constexpr PtrSize getSize()
  51. {
  52. return N;
  53. }
  54. };
  55. /// @}
  56. /// @}
  57. } // end namespace anki
  58. #endif