mn_fixed_array.hpp
Go to the documentation of this file.
1 
20 #ifndef __MINILIB_CONTAINER_FIXED_ARRAY_H__
21 #define __MINILIB_CONTAINER_FIXED_ARRAY_H__
22 
23 #include "../mn_config.hpp"
24 
25 # include <cassert>
26 # include <typeinfo>
27 
28 #include "mn_algorithm.hpp"
29 #include "../mn_allocator.hpp"
30 #include "../mn_def.hpp"
31 #include "../mn_functional.hpp"
32 #include "../mn_typetraits.hpp"
33 
34 #include "../utils/mn_utils.hpp"
35 
36 
37 namespace mn {
38  namespace container {
39 
40 
41 
50  template<typename T, size_t N>
52  public:
54 
55  using value_type = T;
56  using pointer = T*;
57  using const_pointer = const T*;
58  using reference = T&;
59  using const_reference = const T&;
60  using iterator = T*;
61  using const_iterator = const T*;
62 
65 
66  basic_fixed_array() { if(is_pointer<T>::value) fill(nullptr); else fill(T()); }
67  basic_fixed_array(const value_type& val) { fill(val); }
68  basic_fixed_array(const self_type& other) {
69  memcpy(m_nData, other.m_nData, sizeof(m_nData));
70  }
71 
72 
73  iterator begin() noexcept { return &m_nData[0]; }
74  constexpr const_iterator begin() const noexcept
75  { return (m_nData[0]); }
76 
77  iterator end() noexcept { return (m_nData[N-1]); }
78  constexpr const_iterator end() const noexcept
79  { return (m_nData[N-1]); }
80 
81  reference front() noexcept { return (m_nData[0]); }
82  const_reference front() const noexcept { return (m_nData[0]); }
83 
84  reference back() noexcept { return (m_nData[N-1]); }
85  const_reference back() const noexcept { return (m_nData[N-1]); }
86 
87  size_type size() const noexcept { return N; }
88 
89  reference at(size_type pos) { return m_nData[pos]; }
90  const_reference at(size_type pos) const { return m_nData[pos]; }
91 
92  void fill(const value_type& val) {
93  mn::fill_n<value_type>(begin(), N, val);
94  }
95 
96  void swap(self_type& other) noexcept {
97  swap_ranges(begin(), end(), other.begin());
98  }
99 
101  return m_nData[pos]; }
102 
103  constexpr const_reference operator[](size_type pos) const noexcept {
104  return m_nData[pos];
105  }
106 
107  bool is_equele(const self_type& other) {
108  for(int i = 0; i<N; i++)
109  if(m_nData[i] != other.m_nData[i]) return false;
110  return true;
111  }
112 
113  private:
115  };
116 
117  // Array comparisons.
118  template<typename T, size_t N>
120  return a.is_equele(b);
121  }
122 
123  template<typename T, size_t N>
125  return !(a.is_equele(b));
126  }
127 
128 
129  template<typename T, size_t N>
131  for(int i = 0; i<N; i++)
132  if(a[i] >= b[i]) return false;
133  return true;
134  }
135 
136  template<typename T, size_t N>
138  for(int i = 0; i<N; i++)
139  if(a[i] > b[i]) return false;
140  return true;
141  }
142 
143  template<typename T, size_t N>
145  for(int i = 0; i<N; i++)
146  if(a[i] <= b[i]) return false;
147  return true;
148  }
149 
150  template<typename T, size_t N>
152  for(int i = 0; i<N; i++)
153  if(a[i] < b[i]) return false;
154  return true;
155  }
156 
157  template<typename T, size_t N>
159  a.swap(b);
160  }
161 
162  template<typename T, size_t N>
163  inline void fill (basic_fixed_array<T, N>& a, const int val) {
164  a.fill(val);
165  }
166 
167  template<typename T, size_t N>
168  inline void zero (basic_fixed_array<T, N>& a) {
169  a.fill(0);
170  }
171 
172  template<typename T, size_t N>
174  }
175 }
176 
177 #endif // __MINILIB_CONTAINER_ARRAY_H__
A standard container for storing a fixed size sequence of elements.
Definition: mn_fixed_array.hpp:51
mn::size_t size_type
Definition: mn_fixed_array.hpp:63
iterator begin() noexcept
Definition: mn_fixed_array.hpp:73
const_reference front() const noexcept
Definition: mn_fixed_array.hpp:82
basic_fixed_array()
Definition: mn_fixed_array.hpp:66
const_reference back() const noexcept
Definition: mn_fixed_array.hpp:85
const_reference at(size_type pos) const
Definition: mn_fixed_array.hpp:90
basic_fixed_array(const self_type &other)
Definition: mn_fixed_array.hpp:68
T value_type
Definition: mn_fixed_array.hpp:55
const T * const_pointer
Definition: mn_fixed_array.hpp:57
iterator end() noexcept
Definition: mn_fixed_array.hpp:77
T & reference
Definition: mn_fixed_array.hpp:58
reference at(size_type pos)
Definition: mn_fixed_array.hpp:89
void fill(const value_type &val)
Definition: mn_fixed_array.hpp:92
value_type m_nData[N]
Definition: mn_fixed_array.hpp:114
basic_fixed_array(const value_type &val)
Definition: mn_fixed_array.hpp:67
constexpr const_reference operator[](size_type pos) const noexcept
Definition: mn_fixed_array.hpp:103
reference operator[](size_type pos) noexcept
Definition: mn_fixed_array.hpp:100
size_type size() const noexcept
Definition: mn_fixed_array.hpp:87
T * iterator
Definition: mn_fixed_array.hpp:60
reference back() noexcept
Definition: mn_fixed_array.hpp:84
void swap(self_type &other) noexcept
Definition: mn_fixed_array.hpp:96
reference front() noexcept
Definition: mn_fixed_array.hpp:81
T * pointer
Definition: mn_fixed_array.hpp:56
mn::ptrdiff_t difference_type
Definition: mn_fixed_array.hpp:64
const T * const_iterator
Definition: mn_fixed_array.hpp:61
constexpr const_iterator begin() const noexcept
Definition: mn_fixed_array.hpp:74
constexpr const_iterator end() const noexcept
Definition: mn_fixed_array.hpp:78
const T & const_reference
Definition: mn_fixed_array.hpp:59
bool is_equele(const self_type &other)
Definition: mn_fixed_array.hpp:107
Basic algorithmens This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniT...
void fill(basic_array< T, TAllocator, TDeleter > &a, const int val)
Definition: mn_array.hpp:330
bool operator<=(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:300
bool operator<(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:292
void swap(basic_any &x, basic_any &y) noexcept
Definition: mn_any.hpp:272
bool operator!=(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:285
bool operator>=(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:316
bool operator>(const basic_array< T, TAllocator, TDeleter > &a, const basic_array< T, TAllocator, TDeleter > &b)
Definition: mn_array.hpp:308
void zero(basic_array< T, TAllocator, TDeleter > &a)
Definition: mn_array.hpp:335
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
fIt2 swap_ranges(fIt1 a, fIt1 b, fIt2 c)
Definition: mn_algorithm.hpp:331
long ptrdiff_t
Definition: mn_def.hpp:49
MN_THREAD_CONFIG_SIZE_TYPE size_t
Definition: mn_def.hpp:48
Definition: mn_typetraits.hpp:349