mn_tuple.hpp
Go to the documentation of this file.
1 
21 #ifndef __MINILIB_BASIC_TUPLE_H__
22 #define __MINILIB_BASIC_TUPLE_H__
23 
24 #include "../mn_config.hpp"
25 #include "../mn_algorithm.hpp"
26 
27 namespace mn {
28  namespace container {
29 
30  template <size_t N, typename T>
31  class basic_tuple {
32  public:
34  using value_type = T;
35  using const_type = const T;
36  using reference = T&;
37  using const_reference = const T&;
38  using pointer = T*;
39  using const_pointer = const T*;
40  using size_type = size_t;
41  using iterator = pointer;
42  using const_iterator = const pointer;
45 
47  mn::fill_n (m_dDate, N, T());
48  }
49 
51  : m_dDate(t.m_dDate) { }
52 
55  : basic_tuple(a, T(), T(), T()) { }
57  : basic_tuple(a, b, T(), T()) { }
59  : basic_tuple(a, b, c, T()) { }
61  m_dDate[0] = a; m_dDate[1] = b; m_dDate[2] = c;
62 
63  fill_n (m_dDate+3, N-3, d);
64  }
65 
66  template <typename U>
68  mn::copy_n ( static_cast<T*>(src.m_dDate), N, m_dDate);
69  }
70 
71  iterator begin () { return m_dDate; }
72  const_iterator begin () const { return m_dDate; }
73 
74  iterator end () { return m_dDate + N; }
75  const_iterator end () const { return m_dDate + N; }
76 
77  size_type size () const { return N; }
78  size_type max_size () const { return N; }
79 
80  bool empty (void) const { return N == 0; }
81 
82  const_reference at (size_type i) const { return m_dDate[i]; }
83  reference at (size_type i) { return m_dDate[i]; }
84 
85 
86  void swap (self_type& v) {
87  for (uint32_t i = 0; i < N; ++ i)
88  mn::swap (m_dDate[i], v.m_dDate[i]);
89  }
90 
92  const size_t _is_set = min (v.size(), N);
93  mn::copy_n (v.begin(), _is_set, begin());
94  mn::fill_n (begin()+_is_set, N-_is_set, T());
95  return *this;
96  }
97 
98  self_type& assign (const self_type& src) {
99  mn::copy_n (src.begin(), N, begin());
100  return *this;
101  }
102 
103 
104  template <typename U>
106  mn::copy_n ( static_cast<T*>(src.m_dDate), N, m_dDate);
107 
108  return *this;
109  }
111  return assign(src);
112  }
113 
115  return assign(v);
116  }
117 
119  for (uint32_t i = 0; i < min(N, v.size()); ++ i)
120  m_dDate[i] += v.begin()[i];
121  return *this;
122  }
123 
125  for (uint32_t i = 0; i < min(N, v.size()); ++ i)
126  _v[i] -= v.begin()[i];
127  return *this;
128  }
129 
131  for (uint32_t i = 0; i < min(N, v.size()); ++ i)
132  m_dDate[i] *= v.begin()[i];
133  return *this;
134  }
135 
137  for (uint32_t i = 0; i < min(N, v.size()); ++ i)
138  m_dDate[i] /= v.begin()[i];
139  return *this;
140  }
141 
142 
144  for (uint32_t i = 0; i < N; ++ i)
145  m_dDate[i] += v;
146  return *this;
147  }
148 
150  for (uint32_t i = 0; i < N; ++ i)
151  m_dDate[i] -= v;
152  return *this;
153  }
154 
156  for (uint32_t i = 0; i < N; ++ i)
157  m_dDate[i] *= v;
158  return *this;
159  }
160 
162  for (uint32_t i = 0; i < N; ++ i)
163  m_dDate[i] /= v;
164  return *this;
165  }
166 
168  self_type _result;
169  for (uint32_t i = 0; i < N; ++ i)
170  _result[i] = m_dDate[i] + v;
171  return _result;
172  }
173 
175  self_type _result;
176  for (uint32_t i = 0; i < N; ++ i)
177  _result[i] = m_dDate[i] - v;
178  return _result;
179  }
180 
182  self_type _result;
183  for (uint32_t i = 0; i < N; ++ i)
184  _result[i] = m_dDate[i] * v;
185  return _result;
186  }
187 
189  self_type _result;
190  for (uint32_t i = 0; i < N; ++ i)
191  _result[i] = m_dDate[i] / v;
192  return _result;
193  }
194 
197  private:
198  T m_dDate[N];
199  };
200 
201  template <size_t N, typename T, typename U>
202  inline bool operator == (const basic_basic_tuple<N,T>& a, const basic_basic_tuple<N, U>& b) {
203  for (uint32_t i = 0; i < N; ++ i)
204  if (a[i] != b[i]) return false;
205  return true;
206  }
207 
208  template <size_t N, typename T, typename U>
209  inline bool operator != (const basic_basic_tuple<N,T>& a, const basic_basic_tuple<N, U>& b) {
210  for (uint32_t i = 0; i < N; ++ i)
211  if (a[i] == b[i]) return false;
212  return true;
213  }
214 
215  template <size_t N, typename T, typename U>
216  inline bool operator < (const basic_tuple<N,T>& a, const basic_tuple<N, U>& b) {
217  for (uint32_t i = 0; i < N; ++ i)
218  if (a[i] >= b[i]) return false;
219  return true;
220  }
221 
222  template <size_t N, typename T, typename U>
223  inline bool operator > (const basic_tuple<N,T>& a, const basic_tuple<N, U>& b) {
224  for (uint32_t i = 0; i < N; ++ i)
225  if (a[i] <= b[i]) return false;
226  return true;
227  }
228 
229  template <size_t N, typename T, typename U>
230  inline bool operator <= (const basic_tuple<N,T>& a, const basic_tuple<N, U>& b) {
231  for (uint32_t i = 0; i < N; ++ i)
232  if (a[i] > b[i]) return false;
233  return true;
234  }
235 
236  template <size_t N, typename T, typename U>
237  inline bool operator >= (const basic_tuple<N,T>& a, const basic_tuple<N, U>& b) {
238  for (uint32_t i = 0; i < N; ++ i)
239  if (a[i] < b[i]) return false;
240  return true;
241  }
242 
243  template <size_t N, typename T, typename U>
245  for (uint32_t i = 0; i < N; ++ i)
246  a[i] = T(a[i] + b[i]);
247  return a;
248  }
249 
250  template <size_t N, typename T, typename U>
252  for (uint32_t i = 0; i < N; ++ i)
253  a[i] = T(a[i] - b[i]);
254  return a;
255  }
256 
257  template <size_t N, typename T, typename U>
259  for (uint32_t i = 0; i < N; ++ i)
260  a[i] = T(a[i] * b[i]);
261  return a;
262  }
263 
264  template <size_t N, typename T, typename U>
266  for (uint32_t i = 0; i < N; ++ i)
267  a[i] = T(a[i] / b[i]);
268  return a;
269  }
270 
271  template <size_t N, typename T, typename U>
273  basic_tuple<N,T> result;
274  for (uint32_t i = 0; i < N; ++ i)
275  result[i] = T(a[i] + b[i]);
276  return result;
277  }
278 
279  template <size_t N, typename T, typename U>
281  basic_tuple<N,T> result;
282  for (uint32_t i = 0; i < N; ++ i)
283  result[i] = T(a[i] - b[i]);
284  return result;
285  }
286 
287  template <size_t N, typename T, typename U>
289  basic_tuple<N,T> result;
290  for (uint32_t i = 0; i < N; ++ i)
291  result[i] = T(a[i] * b[i]);
292  return result;
293  }
294 
295  template <size_t N, typename T, typename U>
297  basic_tuple<N,T> result;
298  for (uint32_t i = 0; i < N; ++ i)
299  result[i] = T(a[i] / b[i]);
300  return result;
301  }
302 
303  template <size_t N, typename T>
305  }
306 }
307 
308 
309 
310 #endif // __MINILIB_BASIC_TUPLE_H__
Definition: mn_initializer_list.hpp:26
constexpr const_iterator begin() const noexcept
Get a pointer from the first element of the list.
Definition: mn_initializer_list.hpp:53
constexpr size_type size() const noexcept
Get the number of elements in the list.
Definition: mn_initializer_list.hpp:47
Definition: mn_tuple.hpp:31
basic_tuple(const_reference a, const_reference b)
Definition: mn_tuple.hpp:56
self_type operator*(const_reference v)
Definition: mn_tuple.hpp:181
iterator end()
Definition: mn_tuple.hpp:74
const_reference operator[](size_type i) const
Definition: mn_tuple.hpp:195
const_reference at(size_type i) const
Definition: mn_tuple.hpp:82
size_type size() const
Definition: mn_tuple.hpp:77
const T & const_reference
Definition: mn_tuple.hpp:37
T * pointer
Definition: mn_tuple.hpp:38
self_type operator/(const_reference v)
Definition: mn_tuple.hpp:188
self_type & operator*=(mn::initializer_list< value_type > v)
Definition: mn_tuple.hpp:130
T value_type
Definition: mn_tuple.hpp:34
basic_tuple(const_reference a, const_reference b, const_reference c)
Definition: mn_tuple.hpp:58
self_type operator-(const_reference v)
Definition: mn_tuple.hpp:174
size_t size_type
Definition: mn_tuple.hpp:40
basic_tuple(const basic_tuple< N, U > &src)
Definition: mn_tuple.hpp:67
T m_dDate[N]
Definition: mn_tuple.hpp:198
bool empty(void) const
Definition: mn_tuple.hpp:80
const pointer const_iterator
Definition: mn_tuple.hpp:42
const_iterator begin() const
Definition: mn_tuple.hpp:72
size_type max_size() const
Definition: mn_tuple.hpp:78
basic_tuple(mn::initializer_list< value_type > v)
Definition: mn_tuple.hpp:53
basic_tuple()
Definition: mn_tuple.hpp:46
basic_tuple(const_reference a)
Definition: mn_tuple.hpp:54
void swap(self_type &v)
Definition: mn_tuple.hpp:86
T & reference
Definition: mn_tuple.hpp:36
const T const_type
Definition: mn_tuple.hpp:35
self_type operator+(const_reference v)
Definition: mn_tuple.hpp:167
reference at(size_type i)
Definition: mn_tuple.hpp:83
pointer iterator
Definition: mn_tuple.hpp:41
self_type & operator-=(mn::initializer_list< value_type > v)
Definition: mn_tuple.hpp:124
self_type & assign(const self_type &src)
Definition: mn_tuple.hpp:98
self_type & assign(mn::initializer_list< value_type > v)
Definition: mn_tuple.hpp:91
self_type & operator/=(mn::initializer_list< value_type > v)
Definition: mn_tuple.hpp:136
basic_tuple(const_reference a, const_reference b, const_reference c, const_reference d)
Definition: mn_tuple.hpp:60
const T * const_pointer
Definition: mn_tuple.hpp:39
self_type & operator+=(mn::initializer_list< value_type > v)
Definition: mn_tuple.hpp:118
const_iterator end() const
Definition: mn_tuple.hpp:75
iterator begin()
Definition: mn_tuple.hpp:71
self_type & operator=(const tuple< N, U > &src)
Definition: mn_tuple.hpp:105
basic_tuple(const self_type &t)
Definition: mn_tuple.hpp:50
Definition: mn_iterator.hpp:125
bool operator<=(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:300
basic_tuple< N, T > & operator+=(basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:244
basic_tuple< N, T > & operator-=(basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:251
bool operator<(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:292
basic_tuple< N, T > operator+(const basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:272
basic_tuple< N, T > operator*(const basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:288
bool operator!=(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:285
basic_tuple< N, T > & operator/=(basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:265
bool operator>=(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:316
basic_tuple< N, T > & operator*=(basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:258
bool operator>(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:308
basic_tuple< N, T > operator-(const basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:280
basic_tuple< N, T > operator/(const basic_tuple< N, T > &a, const basic_tuple< N, U > &b)
Definition: mn_tuple.hpp:296
bool operator==(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:279
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
void fill_n(T *src, size_t n, const T &val)
Definition: mn_algorithm.hpp:142
T min(const T x, const T y)
Definition: mn_algorithm.hpp:307
void swap(TAssignable &a, TAssignable &b)
Definition: mn_algorithm.hpp:312
void copy_n(const T *src, size_t n, T *dest)
Copy N elements from src to dest.
Definition: mn_algorithm.hpp:74
MN_THREAD_CONFIG_SIZE_TYPE size_t
Definition: mn_def.hpp:48