15 #ifndef ROOT7_RHYSD_ARRAY_VIEW_H 16 #define ROOT7_RHYSD_ARRAY_VIEW_H 26 #include <type_traits> 28 #include <initializer_list> 32 inline namespace __ROOT {
40 static bool const value =
false;
42 template<
class T,
size_t N>
57 template<
size_t... Indices >
59 static constexpr
size_t value[
sizeof...(Indices)] = {Indices...};
62 template<
class IndicesType,
size_t Next>
65 template<
size_t... Indices,
size_t Next>
70 template<
class IndicesType,
size_t Next,
size_t Tail>
73 template<
size_t... Indices,
size_t Next,
size_t Tail>
78 template<
size_t First,
size_t Step,
size_t N,
class =
void>
81 template<
size_t First,
size_t Step,
size_t N>
91 template<
size_t First,
size_t Step,
size_t N>
101 template<
size_t First,
size_t Step,
size_t N>
106 typename
std::enable_if<(N > 1 && N % 2 == 0)>
::type 109 typename detail::make_indices_impl<First, Step, N / 2>::type,
114 template<
size_t First,
size_t Step,
size_t N>
119 typename std::enable_if<(N > 1 && N % 2 == 1)>
::type 122 typename detail::make_indices_impl<First, Step, N / 2>::type,
123 First + N / 2 * Step,
124 First + (N - 1) * Step
128 template<
size_t First,
size_t Last,
size_t Step = 1>
133 ((Last - First) + (Step - 1)) / Step
137 template <
size_t Start,
size_t Last,
size_t Step = 1 >
169 : length_(0), data_(
nullptr)
177 template<
size_type N>
179 : length_(
N), data_(
N > 0 ?
a.data() :
nullptr)
184 template<
size_type N>
186 : length_(
N), data_(
N > 0 ? std::addressof(
a[0]) :
nullptr)
188 static_assert(
N > 0,
"Zero-length array is not permitted in ISO C++.");
192 : length_(
v.size()), data_(
v.empty() ?
nullptr :
v.data())
196 : length_(
n), data_(
a)
201 class =
typename std::enable_if<
204 typename std::iterator_traits<InputIterator>::value_type
209 : length_(
std::distance(start, last)), data_(start)
213 : length_(l.size()), data_(
std::begin(l))
222 constexpr const_iterator
begin() const noexcept
226 constexpr const_iterator
end() const noexcept
228 return data_ + length_;
230 constexpr const_iterator
cbegin() const noexcept
234 constexpr const_iterator
cend() const noexcept
242 const_reverse_iterator
rend()
const 250 const_reverse_iterator
crend()
const 258 constexpr size_type
size() const noexcept
262 constexpr size_type
length() const noexcept
270 constexpr
bool empty() const noexcept
274 constexpr const_reference
operator[](size_type
const n)
const noexcept
278 constexpr const_reference
at(size_type
const n)
const 280 if (n >= length_)
throw std::out_of_range(
"array_view::at()");
283 constexpr const_pointer
data() const noexcept
287 constexpr const_reference
front() const noexcept
291 constexpr const_reference
back() const noexcept
293 return *(data_ + length_ - 1);
303 if (pos >= length_ || pos + slicelen >= length_) {
304 throw std::out_of_range(
"array_view::slice()");
306 return array_view<T>{begin() + pos, begin() + pos + slicelen};
310 if (pos >= length_) {
311 throw std::out_of_range(
"array_view::slice()");
317 if (pos >= length_) {
318 throw std::out_of_range(
"array_view::slice()");
326 return array_view<T>{begin() + pos, begin() + pos + slicelen};
342 if ( start >= end() ||
345 static_cast<size_t>(std::distance(start, last > end() ? end() : last)) > length_ - std::distance(begin(), start) ) {
346 throw std::out_of_range(
"array_view::slice()");
352 if (pos < begin() || pos > end()) {
353 throw std::out_of_range(
"array_view::slice()");
359 if (pos < begin() || pos > end()) {
360 throw std::out_of_range(
"array_view::slice()");
384 template<
class Allocator = std::allocator<T>>
385 auto to_vector(Allocator
const& alloc = Allocator{})
const 386 -> std::vector<T, Allocator>
388 return {begin(), end(), alloc};
398 template<
size_t...
I>
400 -> std::array<
T,
sizeof...(I)>
402 return {{(
I < length_ ? *(data_ +
I) : T{} )...}};
413 template<
class ArrayL,
class ArrayR >
415 bool operator_equal_impl(ArrayL
const& lhs,
size_t const lhs_size, ArrayR
const& rhs,
size_t const rhs_size)
417 if (lhs_size != rhs_size) {
421 auto litr = std::begin(lhs);
422 auto ritr = std::begin(rhs);
423 for (; litr != std::end(lhs); ++litr, ++ritr) {
424 if (!(*litr == *ritr)) {
433 template<
class T1,
class T2>
443 class =
typename std::enable_if<
453 template<
class T1,
class T2,
size_t N>
463 class =
typename std::enable_if<
464 is_array<Array>::value
470 return !(lhs == rhs);
476 class =
typename std::enable_if<
477 is_array<Array>::value
489 class =
typename std::enable_if<
490 is_array<Array>::value,
497 return !(rhs == lhs);
504 class =
typename std::enable_if<
515 template<
class T,
size_t N>
529 template<class InputIterator, class Result = array_view<typename std::iterator_traits<InputIterator>::value_type>>
531 Result
make_view(InputIterator begin, InputIterator end)
533 return Result{begin, end};
556 #include <type_traits> 568 static constexpr
int rank = Rank;
569 using reference = ptrdiff_t &;
570 using const_reference =
const ptrdiff_t &;
571 using size_type = size_t;
572 using value_type = ptrdiff_t;
575 std::array<value_type, Rank> m_B;
578 constexpr bounds() noexcept;
580 constexpr bounds(value_type
b) noexcept: m_B{{b}} { };
585 reference operator[](size_type i) noexcept {
return m_B[i]; }
587 constexpr const_reference operator[](
588 size_type i)
const noexcept {
return m_B[i]; };
591 bool operator==(
const bounds &rhs)
const noexcept;
593 bool operator!=(
const bounds &rhs)
const noexcept;
595 bounds
operator+(
const index<rank> &rhs)
const noexcept;
597 bounds
operator-(
const index<rank> &rhs)
const noexcept;
599 bounds &operator+=(
const index<rank> &rhs) noexcept;
601 bounds &operator-=(
const index<rank> &rhs) noexcept;
603 constexpr size_type size()
const noexcept;
605 bool contains(
const index<rank> &idx)
const noexcept;
616 static constexpr
int rank = Rank;
617 using reference = ptrdiff_t &;
618 using const_reference =
const ptrdiff_t &;
619 using size_type = size_t;
620 using value_type = ptrdiff_t;
623 constexpr index() noexcept;
625 constexpr index(value_type) noexcept;
627 constexpr index(
const initializer_list<value_type> &) noexcept;
629 constexpr index(
const index &) noexcept;
631 index &operator=(
const index &) noexcept;
633 reference operator[](size_type component_idx) noexcept;
635 constexpr const_reference operator[](size_type component_idx)
const noexcept;
637 bool operator==(
const index &rhs)
const noexcept;
639 bool operator!=(
const index &rhs)
const noexcept;
641 index
operator+(
const index &rhs)
const noexcept;
643 index
operator-(
const index &rhs)
const noexcept;
645 index &operator+=(
const index &rhs) noexcept;
647 index &operator-=(
const index &rhs) noexcept;
649 index &operator++() noexcept;
651 index operator++(
int) noexcept;
653 index &operator--() noexcept;
655 index operator--(
int) noexcept;
664 template<
typename ValueType,
int Rank = 1>
667 static constexpr
int rank = Rank;
668 using index_type = index<rank>;
669 using bounds_type = bounds<rank>;
670 using size_type =
typename bounds_type::size_type;
671 using value_type = ValueType;
672 using pointer =
typename std::add_pointer_t<value_type>;
673 using reference =
typename std::add_lvalue_reference_t<value_type>;
677 constexpr
explicit array_view(std::vector<ValueType> &cont) noexcept;
679 template<
typename ArrayType>
682 template<
typename ViewValueType>
685 template<
typename Container>
686 constexpr
array_view(bounds_type bounds, Container &cont) noexcept;
688 constexpr
array_view(bounds_type bounds, pointer data) noexcept;
690 template<
typename ViewValueType>
693 constexpr bounds_type bounds()
const noexcept;
694 constexpr size_type size()
const noexcept;
695 constexpr index_type stride()
const noexcept;
697 constexpr pointer
data()
const noexcept;
698 constexpr reference operator[](
const index_type& idx)
const noexcept;
702 #endif // too complex!
constexpr const_pointer data() const noexcept
array_view(InputIterator start, InputIterator last)
constexpr array_view< T > slice_before(iterator const pos) const
constexpr const_iterator cbegin() const noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr const_iterator end() const noexcept
constexpr array_view() noexcept
constexpr array_view< T > slice(check_bound_t, iterator start, iterator last) const
static constexpr check_bound_t check_bound
void Step(const gsl_rng *r, void *xp, double step_size)
constexpr size_type max_size() const noexcept
value_type const * pointer
constexpr const_iterator begin() const noexcept
const_reverse_iterator rend() const
value_type const & reference
constexpr const_reference operator[](size_type const n) const noexcept
constexpr array_view< T > slice_before(size_type const pos) const
array_view(std::initializer_list< T > const &l)
constexpr const_iterator cend() const noexcept
constexpr bool operator_equal_impl(ArrayL const &lhs, size_t const lhs_size, ArrayR const &rhs, size_t const rhs_size)
constexpr array_view< T > slice_before(check_bound_t, iterator const pos) const
constexpr array_view(T const *a, size_type const n) noexcept
constexpr array_view< T > slice(size_type const pos, size_type const slicelen) const
TTime operator-(const TTime &t1, const TTime &t2)
std::reverse_iterator< iterator > reverse_iterator
constexpr auto make_view(Array const &a) -> array_view< typename Array::value_type >
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
auto to_vector(Allocator const &alloc=Allocator{}) const -> std::vector< T, Allocator >
const_reverse_iterator crend() const
array_view(std::vector< T > const &v) noexcept
value_type const * iterator
auto to_array_impl(detail::indices< I... >) const -> std::array< T, sizeof...(I)>
constexpr array_view< T > slice_after(check_bound_t, iterator const pos) const
constexpr const_reference back() const noexcept
const_pointer const data_
const_reverse_iterator rbegin() const
constexpr bool operator==(array_view< T1 > const &lhs, array_view< T2 > const &rhs)
constexpr array_view< T > slice_after(iterator const pos) const
constexpr array_view< T > slice_after(check_bound_t, size_type const pos) const
constexpr array_view< T > slice_after(size_type const pos) const
constexpr array_view< T > slice_before(check_bound_t, size_type const pos) const
array_view(T const (&a)[N]) noexcept
typename make_indices_< Start, Last, Step >::type make_indices
constexpr array_view< T > slice(check_bound_t, size_type const pos, size_type const slicelen) const
value_type const * const_pointer
auto to_array() const -> std::array< T, N >
constexpr size_type length() const noexcept
constexpr const_reference at(size_type const n) const
constexpr bool empty() const noexcept
constexpr array_view< T > slice(iterator start, iterator last) const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
value_type const * const_iterator
ptrdiff_t difference_type
constexpr size_type size() const noexcept
constexpr bool operator!=(array_view< T > const &lhs, Array const &rhs)
value_type const & const_reference
array_view(std::array< T, N > const &a) noexcept
constexpr const_reference front() const noexcept
const_reverse_iterator crbegin() const