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>
5 struct SmallVector {
6 typedef type value_type;
7
8 std::array<type, max_size> store = {0};
9 unsigned size = 0;
10 auto begin() const { return store.begin(); }
11 auto end() const { return store.begin() + size; }
12 auto begin() { return store.begin(); }
13 auto end() { return store.begin() + size; }
14 value_type& operator[] (unsigned i) { return store[i]; }
15 const value_type& operator[] (unsigned i) const { return store[i]; }
16 void push_back( const value_type& thing ){ store[size++] = thing; }
17 template <typename iterator_type, typename other_iterator_type>
18 void insert(iterator_type mbegin, other_iterator_type ibegin, other_iterator_type iend )
19 {
20 for( auto it = ibegin; it != iend; ++it ){
21 *( mbegin + (it - ibegin) ) = *it;
22 }
23 size += (iend - ibegin );
24 }
25 SmallVector() = default;
26 SmallVector( std::initializer_list<value_type>&& values )
27 {
28 insert( begin(), values.begin(), values.end() );
29 }
30 bool operator==( const SmallVector& other ) const
31 {
32 return other.store == this->store;
33 }
34 };
35}
void push_back(const value_type &thing)
Definition SmallVector.h:16
auto end() const
Definition SmallVector.h:11
bool operator==(const SmallVector &other) const
Definition SmallVector.h:30
auto begin() const
Definition SmallVector.h:10
SmallVector(std::initializer_list< value_type > &&values)
Definition SmallVector.h:26
std::array< type, max_size > store
Definition SmallVector.h:8
void insert(iterator_type mbegin, other_iterator_type ibegin, other_iterator_type iend)
Definition SmallVector.h:18
value_type & operator[](unsigned i)
Definition SmallVector.h:14