Embedded Template Library  1.0
 All Classes Files Functions Variables Typedefs Friends Modules Pages
vector.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 
8 Copyright(c) 2014 jwellbelove
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files(the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions :
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 SOFTWARE.
27 ******************************************************************************/
28 
29 #ifndef __ETL_VECTOR__
30 #define __ETL_VECTOR__
31 
32 #include <stddef.h>
33 #include <iterator>
34 
35 #include "ivector.h"
36 #include "container.h"
37 
38 //*****************************************************************************
43 //*****************************************************************************
44 
45 namespace etl
46 {
47  template <typename T, const size_t MAX_SIZE_>
48  //***************************************************************************
54  //***************************************************************************
55  class vector : public ivector<T>
56  {
57  public:
58 
59  static const size_t MAX_SIZE = MAX_SIZE_;
60 
61  //*************************************************************************
63  //*************************************************************************
65  : ivector<T>(buffer, MAX_SIZE)
66  {
67  }
68 
69  //*************************************************************************
72  //*************************************************************************
73  explicit vector(size_t initialSize)
74  : ivector<T>(buffer, MAX_SIZE)
75  {
76  ivector<T>::resize(initialSize);
77  }
78 
79  //*************************************************************************
83  //*************************************************************************
84  vector(size_t initialSize, typename ivector<T>::parameter_t value)
85  : ivector<T>(buffer, MAX_SIZE)
86  {
87  ivector<T>::resize(initialSize, value);
88  }
89 
90  //*************************************************************************
95  //*************************************************************************
96  template <typename TIterator>
97  vector(TIterator first, TIterator last)
98  : ivector<T>(buffer, MAX_SIZE)
99  {
100  ivector<T>::assign(first, last);
101  }
102 
103  //*************************************************************************
105  //*************************************************************************
106  vector& operator = (const vector& rhs)
107  {
108  ivector<T>::assign(rhs.cbegin(), rhs.cend());
109 
110  return *this;
111  }
112 
113  //*************************************************************************
115  //*************************************************************************
116  void swap(vector& other)
117  {
118  std::swap_ranges(etl::begin(buffer), etl::end(buffer), etl::begin(other.buffer));
119  std::swap(this->current_size, other.current_size);
120  }
121 
122  private:
123 
124  T buffer[MAX_SIZE];
125  };
126 
127  //*************************************************************************
129  //*************************************************************************
130  template <typename T, const size_t MAX_SIZE>
132  {
133  first.swap(second);
134  }
135 }
136 
137 #endif
void swap(vector &other)
Swap.
Definition: vector.h:116
Definition: ivector.h:54
void swap(etl::bitset< N > &lhs, etl::bitset< N > &rhs)
swap
Definition: bitset.h:1200
vector(size_t initialSize)
Definition: vector.h:73
Definition: algorithm.h:43
vector(size_t initialSize, typename ivector< T >::parameter_t value)
Definition: vector.h:84
Definition: vector.h:55
TContainer::iterator end(TContainer &container)
Definition: container.h:95
TContainer::iterator begin(TContainer &container)
Definition: container.h:45
const_iterator cend() const
Definition: ivector.h:144
vector & operator=(const vector &rhs)
Assignment operator.
Definition: vector.h:106
vector()
Constructor.
Definition: vector.h:64
const_iterator cbegin() const
Definition: ivector.h:135
vector(TIterator first, TIterator last)
Definition: vector.h:97
size_type current_size
The current number of elements in the vector.
Definition: vector_base.h:217
void resize(size_t newSize, T value=T())
Definition: ivector.h:210
void assign(TIterator first, TIterator last)
Definition: ivector.h:354