#ifndef LOGNGROWTH_ARRAY_H__ #define LOGNGROWTH_ARRAY_H__ #include "Common.h" #include "LogNGrowthArrayImpl.h" namespace Arrays { template class LogNGrowthArray { public: typedef T value_type; typedef T& reference; typedef const T& const_reference; explicit LogNGrowthArray(const size_type size) : impl_(size) {} LogNGrowthArray(const LogNGrowthArray& other) : impl_(other.size()) { impl_.fill_from(other.impl_); } LogNGrowthArray& operator=(const LogNGrowthArray& other) { LogNGrowthArray arr_copy(other); impl_.swap(arr_copy.impl_); return *this; } size_type size() const { return impl_.size_; } size_type content() const { return impl_.content_; } bool empty() const { return content() == 0; } reference operator[] (const size_type n) { if (n == size()-1) impl_.grow(size()*2); if (n >= content()) impl_.content_ = n+1; return impl_.element(n); } const_reference operator[] (const size_type n) const { return const_cast(*this)[n]; } reference at(const size_type pos) { if (pos >= size()) throw OutOfRange(); return (*this)[pos]; } const_reference at(const size_type pos) const { return const_cast(*this).at(pos); } private: LogNGrowthArrayImpl impl_; }; } #endif