AmpGen 2.1
Loading...
Searching...
No Matches
SmallVector.h
Go to the documentation of this file.
1#include <array>
2
3namespace AmpGen {
4 template <typename type, unsigned max_size> struct SmallVector {
5 typedef type value_type;
6
7 std::array<type, max_size> store = {0};
8 unsigned size = 0;
9 auto begin() const { return store.begin(); }
10 auto end() const { return store.begin() + size; }
11 auto begin() { return store.begin(); }
12 auto end() { return store.begin() + size; }
13 value_type &operator[](unsigned i) { return store[i]; }
14 const value_type &operator[](unsigned i) const { return store[i]; }
15 void push_back(const value_type &thing) { store[size++] = thing; }
16 template <typename iterator_type, typename other_iterator_type> void insert(iterator_type mbegin, other_iterator_type ibegin, other_iterator_type iend) {
17 for(auto it = ibegin; it != iend; ++it) { *(mbegin + (it - ibegin)) = *it; }
18 size += (iend - ibegin);
19 }
20 SmallVector() = default;
21 SmallVector(std::initializer_list<value_type> &&values) { insert(begin(), values.begin(), values.end()); }
22 bool operator==(const SmallVector &other) const { return other.store == this->store; }
23 };
24}
const value_type & operator[](unsigned i) const
Definition SmallVector.h:14
void push_back(const value_type &thing)
Definition SmallVector.h:15
auto end() const
Definition SmallVector.h:10
bool operator==(const SmallVector &other) const
Definition SmallVector.h:22
auto begin() const
Definition SmallVector.h:9
SmallVector(std::initializer_list< value_type > &&values)
Definition SmallVector.h:21
std::array< type, max_size > store
Definition SmallVector.h:7
void insert(iterator_type mbegin, other_iterator_type ibegin, other_iterator_type iend)
Definition SmallVector.h:16
value_type & operator[](unsigned i)
Definition SmallVector.h:13