From d66e30b4c97929ecb8ddc0177c72f7ca2e3faa41 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Tue, 6 Sep 2011 12:03:10 -0600 Subject: [PATCH] Added a Vector::front() method, to mimic std::vector and other STL containers. --- include/Array.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/Array.h b/include/Array.h index 17c312a0fb..d54620b9d1 100644 --- a/include/Array.h +++ b/include/Array.h @@ -97,6 +97,8 @@ public: Vector &operator += (E item) {push_back(item); return *this;}; void insert (E); + const E &front() const; + E &front(); E &back(); E pop_back(); E shift(); // aka pop_front @@ -250,6 +252,22 @@ Vector::back() return items[size() - 1]; } +template +const E & +Vector::front() const +{ + assert (size()); + return items[0]; +} + +template +E & +Vector::front() +{ + assert (size()); + return items[0]; +} + template void Vector::prune(E item) -- 2.47.3