1 #ifndef SIPLASPLAS_CONSTEXPR_ARRAYVIEW_HPP 2 #define SIPLASPLAS_CONSTEXPR_ARRAYVIEW_HPP 4 #include "algorithm.hpp" 18 constexpr
ArrayView(T* begin, std::size_t size) :
23 constexpr ArrayView(T* begin, T* end) :
24 ArrayView{begin,
static_cast<std::size_t
>(end - begin)}
27 constexpr ArrayView(std::initializer_list<T> initList) :
28 ArrayView{
const_cast<T*
>(initList.begin()), const_cast<T*>(initList.end())}
31 template<std::
size_t N>
32 constexpr ArrayView(
const T (&array)[N]) :
36 template<std::
size_t N>
37 constexpr ArrayView(
const std::array<T, N>& array) :
38 ArrayView{array.begin(), N}
41 constexpr std::size_t size()
const 46 constexpr T* begin()
const 51 constexpr T* end()
const 53 return _begin + _size;
56 constexpr T*
const cbegin()
const 61 constexpr T*
const cend()
const 66 constexpr ArrayView operator()(std::size_t begin, std::size_t end)
const 68 return { _begin + begin, _begin + end };
71 constexpr T* operator()(std::size_t i)
const 76 constexpr T operator[](std::size_t i)
const 95 constexpr ConstArrayView(
const T* begin,
const T*
end) :
96 ConstArrayView{begin,
static_cast<std::size_t
>(end - begin)}
99 template<std::
size_t N>
100 constexpr ConstArrayView(
const T (&array)[N]) :
101 ConstArrayView{array, N}
104 template<std::
size_t N>
105 constexpr ConstArrayView(
const std::array<T, N>& array) :
106 ConstArrayView{array.begin(), N}
109 constexpr ConstArrayView(std::initializer_list<T> initList) :
110 ConstArrayView{initList.begin(), initList.end()}
113 constexpr std::size_t size()
const 118 constexpr
const T* begin()
const 123 constexpr
const T* end()
const 125 return _begin + _size;
128 constexpr
const T*
const cbegin()
const 133 constexpr
const T*
const cend()
const 138 constexpr ConstArrayView operator()(std::size_t begin, std::size_t end)
const 140 return { _begin + begin, _begin + end };
143 constexpr
const T* operator()(std::size_t i)
const 148 constexpr T operator[](std::size_t i)
const 159 std::ostream& operator<<(std::ostream& os, const ArrayView<T>& arrayView)
163 for(std::size_t i = 0; i < arrayView.size(); ++i)
165 if(i < arrayView.size() - 1)
167 os << arrayView[i] <<
", ";
179 std::ostream& operator<<(std::ostream& os, const ConstArrayView<T>& arrayView)
183 for(std::size_t i = 0; i < arrayView.size(); ++i)
185 if(i < arrayView.size() - 1)
187 os << arrayView[i] <<
", ";
198 inline std::ostream& operator<<(std::ostream& os, const ArrayView<char>& arrayView)
200 for(
const char c : arrayView)
208 inline std::ostream& operator<<(std::ostream& os, const ConstArrayView<char>& arrayView)
210 for(
const char c : arrayView)
218 template<
typename T,
typename U>
222 lhs.begin(), lhs.end(),
223 rhs.begin(), rhs.end()
227 template<
typename T,
typename U>
231 lhs.begin(), lhs.end(),
232 rhs.begin(), rhs.end()
236 template<
typename T,
typename U>
240 lhs.begin(), lhs.end(),
241 rhs.begin(), rhs.end()
245 template<
typename T,
typename U>
249 lhs.begin(), lhs.end(),
250 rhs.begin(), rhs.end()
254 template<
typename T,
typename U>
257 return !(lhs == rhs);
260 template<
typename T,
typename U>
263 return !(lhs == rhs);
266 template<
typename T,
typename U>
269 return !(lhs == rhs);
272 template<
typename T,
typename U>
275 return !(lhs == rhs);
278 template<
typename T, std::
size_t N>
284 template<
typename T, std::
size_t N>
294 #endif // SIPLASPLAS_CONSTEXPR_ARRAYVIEW_HPP Definition: arrayview.hpp:87
Definition: messaging.hpp:8
constexpr bool equal(Begin1 begin1, End1 end1, Begin2 begin2, End2 end2, Compare compare)
Compares if two sequences are equal.
Definition: algorithm.hpp:137
constexpr auto end(const Sequence &sequence)
Returns an iterator pointing to the end of a sequence.
Definition: algorithm.hpp:86
constexpr auto begin(const Sequence &sequence)
Returns an iterator pointing to the beginning of a sequence.
Definition: algorithm.hpp:62
Definition: arrayview.hpp:15