14#ifndef ROOT_RHYSD_SPAN_H
15#define ROOT_RHYSD_SPAN_H
18#if __cplusplus >= 201402L
19#define R__CONSTEXPR_IF_CXX14 constexpr
21#define R__CONSTEXPR_IF_CXX14
34#include <initializer_list>
43 static bool const value =
false;
45template<
class T,
size_t N>
47 static bool const value =
true;
51 static bool const value =
true;
54struct is_array_class<std::initializer_list<T>> {
55 static bool const value =
true;
60template<
size_t... Indices >
62 static constexpr size_t value[
sizeof...(Indices)] = {Indices...};
65template<
class IndicesType,
size_t Next>
68template<
size_t... Indices,
size_t Next>
73template<
class IndicesType,
size_t Next,
size_t Tail>
76template<
size_t... Indices,
size_t Next,
size_t Tail>
81template<
size_t First,
size_t Step,
size_t N,
class =
void>
84template<
size_t First,
size_t Step,
size_t N>
89 typename std::enable_if<(N == 0)>
::type
94template<
size_t First,
size_t Step,
size_t N>
99 typename std::enable_if<(N == 1)>
::type
104template<
size_t First,
size_t Step,
size_t N>
109 typename std::enable_if<(N > 1 && N % 2 == 0)>
::type
112 typename ROOT::Detail::make_indices_impl<First, Step, N / 2>::type,
117template<
size_t First,
size_t Step,
size_t N>
118struct make_indices_impl<
122 typename std::enable_if<(N > 1 && N % 2 == 1)>
::type
125 typename ROOT::Detail::make_indices_impl<First, Step, N / 2>::type,
126 First + N / 2 * Step,
127 First + (N - 1) * Step
131template<
size_t First,
size_t Last,
size_t Step = 1>
136 ((Last - First) + (Step - 1)) / Step
140template <
size_t Start,
size_t Last,
size_t Step = 1 >
148inline namespace __ROOT {
152struct check_bound_t {};
153static constexpr check_bound_t check_bound{};
161 typedef T value_type;
162 typedef value_type
const* pointer;
163 typedef value_type
const* const_pointer;
164 typedef value_type
const& reference;
165 typedef value_type
const& const_reference;
166 typedef value_type
const* iterator;
167 typedef value_type
const* const_iterator;
168 typedef size_t size_type;
169 typedef ptrdiff_t difference_type;
170 typedef std::reverse_iterator<iterator> reverse_iterator;
171 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
176 constexpr span() noexcept
177 : length_(0), data_(
nullptr)
180 constexpr span(span
const&)
noexcept =
default;
181 constexpr span(span &&) noexcept = default;
185 template<size_type
N>
186 span(std::array<
T,
N> const&
a) noexcept
187 : length_(
N), data_(
N > 0 ?
a.data() :
nullptr)
192 template<
size_type N>
193 span(
T const (&
a)[
N]) noexcept
194 : length_(
N), data_(
N > 0 ? std::addressof(
a[0]) :
nullptr)
196 static_assert(
N > 0,
"Zero-length array is not permitted in ISO C++.");
199 span(std::vector<T>
const&
v) noexcept
200 : length_(
v.size()), data_(
v.empty() ?
nullptr :
v.data())
203 constexpr span(
T const*
a, size_type
const n) noexcept
204 : length_(
n), data_(
a)
209 class =
typename std::enable_if<
212 typename std::iterator_traits<InputIterator>::value_type
216 explicit span(InputIterator start, InputIterator last)
217 : length_(std::distance(start, last)), data_(start)
220 span(std::initializer_list<T>
const&
l)
221 : length_(
l.size()), data_(std::begin(
l))
224 span&
operator=(span
const&)
noexcept =
delete;
225 span&
operator=(span &&) noexcept = delete;
230 constexpr const_iterator begin() const noexcept
234 constexpr const_iterator end() const noexcept
236 return data_ + length_;
238 constexpr const_iterator cbegin() const noexcept
242 constexpr const_iterator cend() const noexcept
246 const_reverse_iterator rbegin()
const
250 const_reverse_iterator rend()
const
254 const_reverse_iterator crbegin()
const
258 const_reverse_iterator crend()
const
266 constexpr size_type size() const noexcept
270 constexpr size_type length() const noexcept
274 constexpr size_type max_size() const noexcept
278 constexpr bool empty() const noexcept
282 constexpr const_reference operator[](size_type
const n)
const noexcept
286 constexpr const_reference at(size_type
const n)
const
291 return n >= length_ ?
throw std::out_of_range(
"span::at()") : *(data_ +
n);
293 constexpr const_pointer data() const noexcept
297 constexpr const_reference front() const noexcept
301 constexpr const_reference back() const noexcept
303 return *(data_ + length_ - 1);
311 constexpr span<T> slice(check_bound_t, size_type
const pos, size_type
const slicelen)
const
318 return pos >= length_ || pos + slicelen >= length_ ?
throw std::out_of_range(
"span::slice()") : span<
T>{begin() + pos, begin() + pos + slicelen};
320 constexpr span<T> slice_before(check_bound_t, size_type
const pos)
const
327 return pos >= length_ ? std::out_of_range(
"span::slice()") : span<
T>{begin(), begin() + pos};
329 constexpr span<T> slice_after(check_bound_t, size_type
const pos)
const
336 return pos >= length_ ? std::out_of_range(
"span::slice()") : span<
T>{begin() + pos, end()};
340 constexpr span<T> slice(size_type
const pos, size_type
const slicelen)
const
342 return span<T>{begin() + pos, begin() + pos + slicelen};
344 constexpr span<T> slice_before(size_type
const pos)
const
346 return span<T>{begin(), begin() + pos};
348 constexpr span<T> slice_after(size_type
const pos)
const
350 return span<T>{begin() + pos, end()};
356 constexpr span<T> slice(check_bound_t, iterator start, iterator last)
const
366 return ( start >= end() ||
369 static_cast<size_t>(std::distance(start, last > end() ? end() : last)) > length_ - std::distance(begin(), start) ) ?
throw std::out_of_range(
"span::slice()") : span<
T>{start, last > end() ? end() : last};
371 constexpr span<T> slice_before(check_bound_t, iterator
const pos)
const
378 return pos < begin() || pos > end() ?
throw std::out_of_range(
"span::slice()") : span<
T>{begin(), pos > end() ? end() : pos};
380 constexpr span<T> slice_after(check_bound_t, iterator
const pos)
const
387 return pos < begin() || pos > end() ?
throw std::out_of_range(
"span::slice()") : span<
T>{pos < begin() ? begin() : pos, end()};
391 constexpr span<T> slice(iterator start, iterator last)
const
393 return span<T>{start, last};
395 constexpr span<T> slice_before(iterator
const pos)
const
397 return span<T>{begin(), pos};
399 constexpr span<T> slice_after(iterator
const pos)
const
401 return span<T>{pos, end()};
409 template<
class Allocator = std::allocator<T>>
410 auto to_vector(Allocator
const& alloc = Allocator{})
const
411 -> std::vector<T, Allocator>
413 return {begin(), end(), alloc};
417 auto to_array() const
423 template<
size_t...
I>
425 -> std::array<
T,
sizeof...(I)>
427 return {{(
I < length_ ? *(data_ +
I) :
T{} )...}};
431 size_type
const length_;
432 const_pointer
const data_;
442template<
class ArrayL,
class ArrayR >
444bool operator_equal_impl(ArrayL
const& lhs,
size_t const lhs_size, ArrayR
const& rhs,
size_t const rhs_size)
446 if (lhs_size != rhs_size) {
450 auto litr = std::begin(lhs);
451 auto ritr = std::begin(rhs);
452 for (; litr != std::end(lhs); ++litr, ++ritr) {
453 if (!(*litr == *ritr)) {
464inline namespace __ROOT {
466template<
class T1,
class T2>
468bool operator==(span<T1>
const& lhs, span<T2>
const& rhs)
476 class =
typename std::enable_if<
486template<
class T1,
class T2,
size_t N>
496 class =
typename std::enable_if<
497 is_array<Array>::value
503 return !(lhs == rhs);
509 class =
typename std::enable_if<
510 is_array<Array>::value
522 class =
typename std::enable_if<
523 is_array<Array>::value,
530 return !(rhs == lhs);
537 class =
typename std::enable_if<
542auto make_view(
Array const&
a)
543-> span<typename Array::value_type>
548template<
class T,
size_t N>
550span<T> make_view(
T const (&
a)[
N])
557span<T> make_view(
T const* p,
typename span<T>::size_type
const n)
559 return span<T>{p,
n};
562template<class InputIterator, class Result = span<typename std::iterator_traits<InputIterator>::value_type>>
564Result make_view(InputIterator begin, InputIterator end)
566 return Result{begin, end};
571span<T> make_view(std::initializer_list<T>
const&
l)
589#include <type_traits>
601 static constexpr int rank = Rank;
602 using reference = ptrdiff_t &;
603 using const_reference =
const ptrdiff_t &;
604 using size_type = size_t;
605 using value_type = ptrdiff_t;
608 std::array<value_type, Rank> m_B;
611 constexpr bounds() noexcept;
613 constexpr bounds(value_type
b) noexcept: m_B{{
b}} { };
618 reference operator[](size_type i)
noexcept {
return m_B[i]; }
620 constexpr const_reference operator[](
621 size_type i)
const noexcept {
return m_B[i]; };
624 bool operator==(
const bounds &rhs)
const noexcept;
626 bool operator!=(
const bounds &rhs)
const noexcept;
628 bounds
operator+(
const index<rank> &rhs)
const noexcept;
630 bounds
operator-(
const index<rank> &rhs)
const noexcept;
632 bounds &
operator+=(
const index<rank> &rhs)
noexcept;
634 bounds &operator-=(
const index<rank> &rhs)
noexcept;
636 constexpr size_type size() const noexcept;
638 bool contains(const index<rank> &idx) const noexcept;
649 static constexpr int rank = Rank;
650 using reference = ptrdiff_t &;
651 using const_reference =
const ptrdiff_t &;
652 using size_type = size_t;
653 using value_type = ptrdiff_t;
656 constexpr index() noexcept;
658 constexpr index(value_type) noexcept;
660 constexpr index(const initializer_list<value_type> &) noexcept;
662 constexpr index(const index &) noexcept;
664 index &operator=(const index &) noexcept;
666 reference operator[](size_type component_idx) noexcept;
668 constexpr const_reference operator[](size_type component_idx) const noexcept;
670 bool operator==(const index &rhs) const noexcept;
672 bool operator!=(const index &rhs) const noexcept;
674 index operator+(const index &rhs) const noexcept;
676 index operator-(const index &rhs) const noexcept;
678 index &operator+=(const index &rhs) noexcept;
680 index &operator-=(const index &rhs) noexcept;
682 index &operator++() noexcept;
684 index operator++(
int) noexcept;
686 index &operator--() noexcept;
688 index operator--(
int) noexcept;
690 index operator+() const noexcept;
692 index operator-() const noexcept;
697template<typename ValueType,
int Rank = 1>
700 static constexpr int rank = Rank;
701 using index_type = index<rank>;
702 using bounds_type = bounds<rank>;
703 using size_type =
typename bounds_type::size_type;
704 using value_type = ValueType;
705 using pointer =
typename std::add_pointer_t<value_type>;
706 using reference =
typename std::add_lvalue_reference_t<value_type>;
708 constexpr span() noexcept;
710 constexpr explicit span(std::vector<ValueType> &cont) noexcept;
712 template<typename ArrayType>
713 constexpr explicit span(ArrayType &data) noexcept;
715 template<typename ViewValueType>
716 constexpr span(const span<ViewValueType, rank> &rhs) noexcept;
718 template<typename Container>
719 constexpr span(bounds_type bounds, Container &cont) noexcept;
721 constexpr span(bounds_type bounds, pointer data) noexcept;
723 template<typename ViewValueType>
724 span &operator=(const span<ViewValueType, rank> &rhs) noexcept;
726 constexpr bounds_type bounds() const noexcept;
727 constexpr size_type size() const noexcept;
728 constexpr index_type stride() const noexcept;
730 constexpr pointer data() const noexcept;
731 constexpr reference operator[](const index_type& idx) const noexcept;
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Binding & operator=(OUT(*fun)(void))
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
std::string & operator+=(std::string &left, const TString &right)
TTime operator-(const TTime &t1, const TTime &t2)
R__CONSTEXPR_IF_CXX14 bool operator_equal_impl(ArrayL const &lhs, size_t const lhs_size, ArrayR const &rhs, size_t const rhs_size)
typename make_indices_< Start, Last, Step >::type make_indices
void Step(const gsl_rng *r, void *xp, double step_size)
Namespace for new ROOT classes and functions.
#define R__CONSTEXPR_IF_CXX14
static constexpr size_t value[sizeof...(Indices)]