1 /* Copyright 2015 OpenMarket Ltd
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
22 template<typename T, std::size_t max_size>
25 List() : _end(_data) {}
28 typedef T const * const_iterator;
30 T * begin() { return _data; }
31 T * end() { return _end; }
32 T const * begin() const { return _data; }
33 T const * end() const { return _end; }
38 bool empty() const { return _end == _data; }
41 * The number of items in the list.
43 std::size_t size() const { return _end - _data; }
45 T & operator[](std::size_t index) { return _data[index]; }
47 T const & operator[](std::size_t index) const { return _data[index]; }
50 * Erase the item from the list at the given position.
61 * Make space for an item in the list at a given position.
62 * If inserting the item makes the list longer than max_size then
63 * the end of the list is discarded.
64 * Returns the where the item is inserted.
67 if (_end != _data + max_size) {
69 } else if (pos == _end) {
81 * Make space for an item in the list at the start of the list
83 T * insert() { return insert(begin()); }
86 * Insert an item into the list at a given position.
87 * If inserting the item makes the list longer than max_size then
88 * the end of the list is discarded.
89 * Returns the where the item is inserted.
91 T * insert(T * pos, T const & value) {
97 List<T, max_size> & operator=(List<T, max_size> const & other) {
101 T * this_pos = _data;
102 T * const other_pos = other._data;
103 while (other_pos != other._end) {
119 #endif /* OLM_LIST_HH_ */