Skip to content

Commit

Permalink
containers/Array.hpp cleanup and remove data initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar authored and LorenzMeier committed Jan 20, 2019
1 parent 7008558 commit 652c9df
Showing 1 changed file with 23 additions and 73 deletions.
96 changes: 23 additions & 73 deletions src/include/containers/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,13 @@
namespace px4
{

template <typename TYPE, size_t N>
template <class T, size_t N>
class Array
{
typedef TYPE &reference;
typedef const TYPE &const_reference;
typedef TYPE *iterator;
typedef const TYPE *const_iterator;

public:
Array() = default;

bool push_back(const TYPE &x)
bool push_back(const T &x)
{
if (_size == N) {
_overflow = true;
Expand All @@ -73,84 +68,39 @@ class Array
}
}

reference operator[](size_t n)
void erase(T *item)
{
return _items[n];
}

const_reference operator[](size_t n) const
{
return _items[n];
}

reference at(size_t n)
{
return _items[n];
}

const_reference at(size_t n) const
{
return _items[n];
}

size_t size() const
{
return _size;
}

size_t max_size() const
{
return N;
}

size_t capacity() const
{
return N;
}
if (item - _items < static_cast<int>(_size)) {
--_size;

bool empty() const
{
return _size == 0;
for (T *it = item; it != &_items[_size]; ++it) {
*it = *(it + 1);
}
}
}

bool is_overflowed()
{
return _overflow;
}
T &operator[](size_t n) { return _items[n]; }
const T &operator[](size_t n) const { return _items[n]; }

iterator begin()
{
return &_items[0];
}
T &at(size_t n) { return _items[n]; }
const T &at(size_t n) const { return _items[n]; }

iterator end()
{
return &_items[_size];
}
size_t size() const { return _size; }
size_t max_size() const { return N; }
size_t capacity() const { return N; }

const_iterator begin() const
{
return &_items[0];
}
bool empty() const { return _size == 0; }

const_iterator end() const
{
return &_items[_size];
}
bool is_overflowed() { return _overflow; }

void erase(iterator item)
{
if (item - _items < static_cast<int>(_size)) {
--_size;
T *begin() { return &_items[0]; }
T *end() { return &_items[_size]; }

for (iterator it = item; it != &_items[_size]; ++it) {
*it = *(it + 1);
}
}
}
const T *begin() const { return &_items[0]; }
const T *end() const { return &_items[_size]; }

private:
TYPE _items[N] {};
T _items[N];
size_t _size{0};
bool _overflow{false};
};
Expand Down

0 comments on commit 652c9df

Please sign in to comment.