1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
| #ifndef __LiNEAR_TABLE_H__ #define __LiNEAR_TABLE_H__
#include <initializer_list>
template<class _Ty, size_t _Size> class Array;
template<class _Ty, size_t _Size> class Array { public: typedef std::random_access_iterator_tag iterator_category; typedef _Ty value_type; typedef _Ty* iterator; typedef const _Ty* const_iterator; typedef _Ty& reference; typedef const _Ty& const_reference; public: explicit Array() noexcept; explicit Array(const _Ty&) noexcept; explicit Array(_Ty&) noexcept; explicit Array(_Ty&&) noexcept; explicit Array(const _Ty*) noexcept; Array(const std::initializer_list<_Ty>&) noexcept; Array(std::initializer_list<_Ty>&) noexcept; Array(std::initializer_list<_Ty>&&) noexcept; Array(const Array&) noexcept; ~Array() noexcept; iterator begin() const noexcept; iterator last() const noexcept; iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator clast() const noexcept; constexpr const_iterator cend() const noexcept; constexpr size_t size() const noexcept; value_type max() const; value_type min() const; void remove() const; const_reference operator[](const size_t&) const noexcept; reference operator[](const size_t&) noexcept; private: void __init__(const _Ty&); void __init__(const std::initializer_list<_Ty>&); iterator __beg; iterator __ed; }; template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array() noexcept : __beg(new _Ty[_Size]), __ed(__beg + _Size) {}
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( const _Ty & __init_value ) noexcept { __init__(__init_value); }
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( _Ty &__init_value ) noexcept : Array(std::move(__init_value)) {}
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( _Ty &&__init_value ) noexcept : Array() { __init__(__init_value); }
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( const _Ty *__Arr ) noexcept : Array() { std::copy( __Arr, __Arr + _Size, __beg ); }
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( const std::initializer_list<_Ty>& _init_lst ) noexcept : Array() { __init__(_init_lst); }
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( std::initializer_list<_Ty>& _init_lst ) noexcept : Array(std::move(_init_lst)) {}
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( std::initializer_list<_Ty>&& _init_lst ) noexcept : Array() { __init__(_init_lst); }
template<class _Ty, size_t _Size> Array<_Ty, _Size>::Array( const Array & _another_Arr ) noexcept : Array() { std::copy( _another_Arr.begin(), _another_Arr.end(), __beg ); }
template<class _Ty, size_t _Size> Array<_Ty, _Size>::~Array() noexcept = default;
template<class _Ty, size_t _Size> inline typename Array<_Ty, _Size>::iterator Array<_Ty, _Size>::begin() const noexcept { return __beg; }
template<class _Ty, size_t _Size> inline typename Array<_Ty, _Size>::iterator Array<_Ty, _Size>::last() const noexcept { return __ed - 1; }
template<class _Ty, size_t _Size> inline typename Array<_Ty, _Size>::iterator Array<_Ty, _Size>::end() const noexcept { return __ed; }
template<class _Ty, size_t _Size> inline constexpr typename Array<_Ty, _Size>::const_iterator Array<_Ty, _Size>::cbegin() const noexcept { return __beg; }
template<class _Ty, size_t _Size> inline constexpr typename Array<_Ty, _Size>::const_iterator Array<_Ty, _Size>::clast() const noexcept { return __ed - 1; }
template<class _Ty, size_t _Size> inline constexpr typename Array<_Ty, _Size>::const_iterator Array<_Ty, _Size>::cend() const noexcept { return __ed; }
template<class _Ty, size_t _Size> inline constexpr size_t Array<_Ty, _Size>::size() const noexcept { return _Size; }
template<class _Ty, size_t _Size> _Ty Array<_Ty, _Size>::max() const { _Ty __Cmp = *begin(); for(auto __item: begin()) __Cmp = __Cmp > __item ? __Cmp : __item; return __Cmp; }
template<class _Ty, size_t _Size> _Ty Array<_Ty, _Size>::min() const { _Ty __Cmp = *begin(); for(auto __item: begin()) __Cmp = __Cmp < __item ? __Cmp : __item; return __Cmp; }
template<class _Ty, size_t _Size> inline void Array<_Ty, _Size>::remove() const { delete[] __beg; }
template<class _Ty, size_t _Size> inline typename Array<_Ty, _Size>::const_reference Array<_Ty, _Size>::operator[](const size_t &__index) const noexcept { return *(begin() + __index); }
template<class _Ty, size_t _Size> inline typename Array<_Ty, _Size>::reference Array<_Ty, _Size>::operator[](const size_t &__index) noexcept { return const_cast<_Ty&>( static_cast<const Array&>(*this) [__index] ); }
template<class _Ty, size_t _Size> inline void Array<_Ty, _Size>::__init__(const _Ty &__init_value) { auto __item = begin() - 1; for(; ++__item != __ed;) *__item = __init_value; }
template<class _Ty, size_t _Size> inline void Array<_Ty, _Size>::__init__( const std::initializer_list<_Ty> &_init_lst ) { size_t __index = -1; for(auto __item: _init_lst) *(begin() + (++__index)) = __item; }
#endif
|