Vector.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_UTIL_VECTOR_H
  6. #define ANKI_UTIL_VECTOR_H
  7. #include "anki/util/Assert.h"
  8. #include "anki/util/Allocator.h"
  9. #include <vector>
  10. namespace anki {
  11. /// @addtogroup util_containers
  12. /// @{
  13. /// A semi-custom implementation of vector
  14. template<typename T, typename TAlloc = HeapAllocator<T>>
  15. class Vector: public std::vector<T, TAlloc>
  16. {
  17. public:
  18. using Base = std::vector<T, TAlloc>;
  19. using Base::Base;
  20. using Base::operator=;
  21. typename Base::reference operator[](typename Base::size_type i)
  22. {
  23. ANKI_ASSERT(i < Base::size() && "Vector out of bounds");
  24. return Base::operator[](i);
  25. }
  26. typename Base::const_reference operator[](typename Base::size_type i) const
  27. {
  28. ANKI_ASSERT(i < Base::size() && "Vector out of bounds");
  29. return Base::operator[](i);
  30. }
  31. PtrSize getSizeInBytes() const
  32. {
  33. return Base::size() * sizeof(T);
  34. }
  35. };
  36. /// @}
  37. } // end namespace anki
  38. #endif