#pragma once #include <stdexcept> #include "iterator/VectorIterator.hpp" #include "array/Helpers.hpp" #include "../common/compat.hpp" #include "../common/errors.hpp" #include "string.h" namespace sprawl { namespace collections { template<typename T, ssize_t size> class Array; } } template<typename T, ssize_t size> class sprawl::collections::Array { public: typedef VectorIterator<T, Array<T, size>> iterator; typedef VectorIterator<T, Array<T, size>> const const_iterator; T& operator[](ssize_t index) { if (index < 0) { index += size; } return m_array[index]; } sprawl::ErrorState<T&> At(ssize_t index) { if (index < 0) { index += size; } if(index > size) { SPRAWL_THROW_EXCEPTION(sprawl::OutOfRangeError()); } return m_array[index]; } T const& operator[](ssize_t index) const { if (index < 0) { index += size; } return m_array[index]; } sprawl::ErrorState<T const&> At(ssize_t index) const { if (index < 0) { index += size; } if(index > size) { SPRAWL_THROW_EXCEPTION(sprawl::OutOfRangeError()); } return m_array[index]; } T& Front() { return m_array[0]; } T& Back() { return m_array[size -1]; } T const& Front() const { return m_array[0]; } T const& Back() const { return m_array[size -1]; } T* Data() { return m_array; } ssize_t Size() { return size; } bool Empty() { return size == 0; } iterator begin() { return iterator(m_array, this); } iterator end() { return iterator(m_array + size, this); } const_iterator cbegin() const { return const_iterator(m_array, this); } const_iterator cend() const { return const_iterator(m_array + size, this); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } void Fill(T const& value) { for(ssize_t i = 0; i < size; ++i) { m_array[i] = value; } } private: T m_array[size]; };
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 18645 | brandon_m_bare | Integrated latest version of libsprawl. | ||
#1 | 15089 | brandon_m_bare | First integration of sprawl. | ||
//guest/ShadauxCat/Sprawl/Mainline/collections/Array.hpp | |||||
#2 | 14168 | ShadauxCat |
-Implemented Array -Fixed compile error when calling Vector::Swap() -Fixed missing constness on functions called from const functions in Deque -Added fill, copy, and move constructor unit tests for Vector and Deque, and Swap() unit test for Vector #review-14169 |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |