P4C
The P4 Compiler
Loading...
Searching...
No Matches
dyn_vector.h
1
19#ifndef BF_P4C_LIB_DYN_VECTOR_H_
20#define BF_P4C_LIB_DYN_VECTOR_H_
21
22#include <vector>
23
26template <class T, class _Alloc = std::allocator<T>>
27class dyn_vector : public std::vector<T, _Alloc> {
28 public:
29 using std::vector<T, _Alloc>::vector;
30 typedef typename std::vector<T, _Alloc>::reference reference;
31 typedef typename std::vector<T, _Alloc>::const_reference const_reference;
32 typedef typename std::vector<T, _Alloc>::size_type size_type;
33 typedef typename std::vector<T>::const_iterator const_iterator;
34 reference operator[](size_type n) {
35 if (n >= this->size()) this->resize(n + 1);
36 return this->at(n);
37 }
38 const_reference operator[](size_type n) const {
39 if (n < this->size()) return this->at(n);
40 static const T default_value = T();
41 return default_value;
42 }
43};
44
45#endif /* BF_P4C_LIB_DYN_VECTOR_H_ */
Definition dyn_vector.h:27