15 #ifndef ROOT7_RHYSD_ARRAY_VIEW_H
16 #define ROOT7_RHYSD_ARRAY_VIEW_H
26 #include <type_traits>
28 #include <initializer_list>
38 static bool const value =
false;
40 template<
class T,
size_t N>
55 template<
size_t... Indices >
57 static constexpr
size_t value[
sizeof...(Indices)] = {Indices...};
60 template<
class IndicesType,
size_t Next>
63 template<
size_t... Indices,
size_t Next>
68 template<
class IndicesType,
size_t Next,
size_t Tail>
71 template<
size_t... Indices,
size_t Next,
size_t Tail>
76 template<
size_t First,
size_t Step,
size_t N,
class =
void>
79 template<
size_t First,
size_t Step,
size_t N>
89 template<
size_t First,
size_t Step,
size_t N>
99 template<
size_t First,
size_t Step,
size_t N>
104 typename
std::enable_if<(N > 1 && N % 2 == 0)>
::type
107 typename detail::make_indices_impl<First, Step, N / 2>::type,
112 template<
size_t First,
size_t Step,
size_t N>
117 typename
std::enable_if<(N > 1 && N % 2 == 1)>
::type
120 typename detail::make_indices_impl<First, Step, N / 2>::type,
121 First + N / 2 * Step,
122 First + (N - 1) * Step
126 template<
size_t First,
size_t Last,
size_t Step = 1>
131 ((Last - First) + (Step - 1)) / Step
135 template <
size_t Start,
size_t Last,
size_t Step = 1 >
170 constexpr
array_view(array_view
const&) noexcept = default;
171 constexpr array_view(array_view &&) noexcept = default;
176 array_view(
std::array<T, N> const&
a) noexcept
182 template<
size_type N>
186 static_assert(N > 0,
"Zero-length array is not permitted in ISO C++.");
199 class =
typename std::enable_if<
202 typename std::iterator_traits<InputIterator>::value_type
214 array_view&
operator=(array_view
const&) noexcept = delete;
215 array_view& operator=(array_view &&) noexcept = delete;
220 constexpr const_iterator
begin() const noexcept
224 constexpr const_iterator
end() const noexcept
228 constexpr const_iterator
cbegin() const noexcept
232 constexpr const_iterator
cend() const noexcept
240 const_reverse_iterator
rend()
const
248 const_reverse_iterator
crend()
const
256 constexpr size_type
size() const noexcept
260 constexpr size_type
length() const noexcept
268 constexpr
bool empty() const noexcept
272 constexpr const_reference
operator[](size_type
const n)
const noexcept
276 constexpr const_reference
at(size_type
const n)
const
278 if (n >=
length_)
throw std::out_of_range(
"array_view::at()");
281 constexpr const_pointer
data() const noexcept
285 constexpr const_reference
front() const noexcept
289 constexpr const_reference
back() const noexcept
302 throw std::out_of_range(
"array_view::slice()");
309 throw std::out_of_range(
"array_view::slice()");
316 throw std::out_of_range(
"array_view::slice()");
340 if ( start >=
end() ||
344 throw std::out_of_range(
"array_view::slice()");
351 throw std::out_of_range(
"array_view::slice()");
358 throw std::out_of_range(
"array_view::slice()");
382 template<
class Allocator = std::allocator<T>>
383 auto to_vector(Allocator
const& alloc = Allocator{})
const
384 -> std::vector<T, Allocator>
396 template<
size_t... I>
398 ->
std::array<T, sizeof...(I)>
411 template<
class ArrayL,
class ArrayR >
413 bool operator_equal_impl(ArrayL
const& lhs,
size_t const lhs_size, ArrayR
const& rhs,
size_t const rhs_size)
415 if (lhs_size != rhs_size) {
419 auto litr = std::begin(lhs);
420 auto ritr = std::begin(rhs);
421 for (; litr != std::end(lhs); ++litr, ++ritr) {
422 if (!(*litr == *ritr)) {
431 template<
class T1,
class T2>
433 bool operator==(array_view<T1>
const& lhs, array_view<T2>
const& rhs)
441 class =
typename std::enable_if<
446 bool operator==(array_view<T>
const& lhs, Array
const& rhs)
451 template<
class T1,
class T2,
size_t N>
453 bool operator==(array_view<T1>
const& lhs,
T2 const (& rhs)[N])
461 class =
typename std::enable_if<
462 is_array<Array>::value
466 bool operator!=(array_view<T>
const& lhs, Array
const& rhs)
468 return !(lhs == rhs);
474 class =
typename std::enable_if<
475 is_array<Array>::value
479 bool operator==(Array
const& lhs, array_view<T>
const& rhs)
487 class =
typename std::enable_if<
488 is_array<Array>::value,
493 bool operator!=(Array
const& lhs, array_view<T>
const& rhs)
495 return !(rhs == lhs);
502 class =
typename std::enable_if<
507 auto make_view(Array
const&
a)
508 -> array_view<typename Array::value_type>
513 template<
class T,
size_t N>
515 array_view<T> make_view(T
const (&
a)[N])
522 array_view<T> make_view(T
const* p,
typename array_view<T>::size_type
const n)
524 return array_view<T>{p, n};
529 Result make_view(InputIterator
begin, InputIterator
end)
531 return Result{
begin, end};
536 array_view<T> make_view(std::initializer_list<T>
const&
l)
553 #include <type_traits>
565 static constexpr
int rank = Rank;
566 using reference = ptrdiff_t &;
567 using const_reference =
const ptrdiff_t &;
569 using value_type = ptrdiff_t;
572 std::array<value_type, Rank> m_B;
575 constexpr bounds() noexcept;
577 constexpr bounds(value_type b) noexcept: m_B{{b}} { };
582 reference
operator[](size_type i) noexcept {
return m_B[i]; }
585 size_type i)
const noexcept {
return m_B[i]; };
588 bool operator==(
const bounds &rhs)
const noexcept;
590 bool operator!=(
const bounds &rhs)
const noexcept;
592 bounds
operator+(
const index<rank> &rhs)
const noexcept;
594 bounds
operator-(
const index<rank> &rhs)
const noexcept;
596 bounds &operator+=(
const index<rank> &rhs) noexcept;
598 bounds &operator-=(
const index<rank> &rhs) noexcept;
600 constexpr size_type
size() const noexcept;
602 bool contains(const index<rank> &idx) const noexcept;
613 static constexpr
int rank = Rank;
614 using reference = ptrdiff_t &;
615 using const_reference =
const ptrdiff_t &;
617 using value_type = ptrdiff_t;
620 constexpr index() noexcept;
622 constexpr index(value_type) noexcept;
624 constexpr index(const initializer_list<value_type> &) noexcept;
626 constexpr index(const index &) noexcept;
628 index &operator=(const index &) noexcept;
630 reference operator[](size_type component_idx) noexcept;
632 constexpr const_reference operator[](size_type component_idx) const noexcept;
634 bool operator==(const index &rhs) const noexcept;
636 bool operator!=(const index &rhs) const noexcept;
638 index operator+(const index &rhs) const noexcept;
640 index operator-(const index &rhs) const noexcept;
642 index &operator+=(const index &rhs) noexcept;
644 index &operator-=(const index &rhs) noexcept;
646 index &operator++() noexcept;
648 index operator++(
int) noexcept;
650 index &operator--() noexcept;
652 index operator--(
int) noexcept;
654 index operator+() const noexcept;
656 index operator-() const noexcept;
661 template<typename ValueType,
int Rank = 1>
664 static constexpr
int rank = Rank;
665 using index_type = index<rank>;
666 using bounds_type = bounds<rank>;
667 using size_type =
typename bounds_type::size_type;
668 using value_type = ValueType;
669 using pointer =
typename std::add_pointer_t<value_type>;
670 using reference =
typename std::add_lvalue_reference_t<value_type>;
674 constexpr explicit array_view(
std::vector<ValueType> &cont) noexcept;
677 constexpr explicit array_view(ArrayType &
data) noexcept;
680 constexpr array_view(const array_view<ViewValueType, rank> &rhs) noexcept;
683 constexpr array_view(bounds_type bounds, Container &cont) noexcept;
685 constexpr array_view(bounds_type bounds, pointer
data) noexcept;
688 array_view &operator=(const array_view<ViewValueType, rank> &rhs) noexcept;
690 constexpr bounds_type bounds() const noexcept;
691 constexpr size_type
size() const noexcept;
692 constexpr index_type stride() const noexcept;
694 constexpr pointer
data() const noexcept;
695 constexpr reference operator[](const index_type& idx) const noexcept;
699 #endif // too complex!
constexpr array_view< T > slice(iterator start, iterator last) const
Small helper to encapsulate whether to return the value pointed to by the iterator or its address...
const_reverse_iterator crbegin() const
constexpr const_reference operator[](size_type const n) const noexcept
constexpr array_view< T > slice(check_bound_t, size_type const pos, size_type const length) const
value_type const * const_iterator
Double_t distance(const TPoint2 &p1, const TPoint2 &p2)
array_view(std::initializer_list< T > const &l)
const_reverse_iterator rend() const
constexpr const_iterator end() const noexcept
constexpr array_view< T > slice_after(size_type const pos) const
void Step(const gsl_rng *r, void *xp, double step_size)
value_type const * const_pointer
constexpr array_view< T > slice(check_bound_t, iterator start, iterator last) const
const_reverse_iterator crend() const
typename make_indices_< Start, Last, Step >::type make_indices
constexpr size_type length() const noexcept
array_view(InputIterator start, InputIterator last)
constexpr array_view< T > slice_after(check_bound_t, size_type const pos) const
array_view(T const (&a)[N]) noexcept
value_type const & reference
constexpr bool operator_equal_impl(ArrayL const &lhs, size_t const lhs_size, ArrayR const &rhs, size_t const rhs_size)
TTime operator-(const TTime &t1, const TTime &t2)
constexpr const_reference back() const noexcept
constexpr array_view< T > slice_after(check_bound_t, iterator const pos) const
constexpr const_iterator begin() const noexcept
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
constexpr array_view< T > slice_before(size_type const pos) const
static constexpr size_t value[sizeof...(Indices)]
value_type const * iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
array_view & operator=(array_view const &) noexcept=delete
ptrdiff_t difference_type
constexpr const_iterator cbegin() const noexcept
constexpr array_view() noexcept
constexpr size_type size() const noexcept
constexpr array_view< T > slice_before(check_bound_t, size_type const pos) const
constexpr array_view< T > slice_after(iterator const pos) const
constexpr const_pointer data() const noexcept
constexpr const_iterator cend() const noexcept
const_reverse_iterator rbegin() const
constexpr array_view< T > slice_before(check_bound_t, iterator const pos) const
constexpr array_view< T > slice_before(iterator const pos) const
constexpr const_reference front() const noexcept
const_pointer const data_
value_type const & const_reference
auto to_array_impl(detail::indices< I...>) const -> std::array< T, sizeof...(I)>
constexpr size_type max_size() const noexcept
constexpr array_view< T > slice(size_type const pos, size_type const length) const
Bool_t operator==(const TDatime &d1, const TDatime &d2)
constexpr const_reference at(size_type const n) const
value_type const * pointer
auto to_vector(Allocator const &alloc=Allocator{}) const -> std::vector< T, Allocator >
std::reverse_iterator< iterator > reverse_iterator
auto to_array() const -> std::array< T, N >
array_view(std::vector< T > const &v) noexcept
constexpr array_view(T const *a, size_type const n) noexcept
constexpr bool empty() const noexcept