Skip to content

Commit 1aae1e5

Browse files
guyingzhaonikias
authored andcommitted
C++: Add f/Front() and b/Back() to Array to access first/last element
1 parent 464382e commit 1aae1e5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

include/plist/Array.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public :
4343
typedef std::vector<Node*>::const_iterator const_iterator;
4444

4545
Node* operator[](unsigned int index);
46+
Node* Back();
47+
Node* back();
48+
Node* Front();
49+
Node* front();
4650
iterator Begin();
4751
iterator begin();
4852
iterator End();

src/Array.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ Node* Array::operator[](unsigned int array_index)
9090
return _array.at(array_index);
9191
}
9292

93+
Node* Array::Back()
94+
{
95+
return _array.back();
96+
}
97+
98+
Node* Array::back()
99+
{
100+
return _array.back();
101+
}
102+
103+
Node* Array::Front()
104+
{
105+
return _array.front();
106+
}
107+
108+
Node* Array::front()
109+
{
110+
return _array.front();
111+
}
112+
93113
Array::iterator Array::Begin()
94114
{
95115
return _array.begin();

0 commit comments

Comments
 (0)