14#ifndef ROOT_RHYSD_SPAN_H
15#define ROOT_RHYSD_SPAN_H
17#if __cplusplus >= 202002
18# if __has_include(<span>)
23#if !defined(__cpp_lib_span)
26#if __cplusplus >= 201402L
27#define R__CONSTEXPR_IF_CXX14 constexpr
29#define R__CONSTEXPR_IF_CXX14
41#include <initializer_list>
50 static bool const value =
false;
52template<
class T,
size_t N>
54 static bool const value =
true;
58 static bool const value =
true;
61struct is_array_class<std::initializer_list<T>> {
62 static bool const value =
true;
67template<
size_t... Indices >
69 static constexpr size_t value[
sizeof...(Indices)] = {Indices...};
72template<
class IndicesType,
size_t Next>
75template<
size_t... Indices,
size_t Next>
80template<
class IndicesType,
size_t Next,
size_t Tail>
83template<
size_t... Indices,
size_t Next,
size_t Tail>
88template<
size_t First,
size_t Step,
size_t N,
class =
void>
91template<
size_t First,
size_t Step,
size_t N>
96 typename std::enable_if<(N == 0)>
::type
101template<
size_t First,
size_t Step,
size_t N>
106 typename std::enable_if<(N == 1)>
::type
111template<
size_t First,
size_t Step,
size_t N>
116 typename std::enable_if<(N > 1 && N % 2 == 0)>
::type
119 typename ROOT::Detail::make_indices_impl<First, Step, N / 2>::type,
124template<
size_t First,
size_t Step,
size_t N>
125struct make_indices_impl<
129 typename std::enable_if<(N > 1 && N % 2 == 1)>
::type
132 typename ROOT::Detail::make_indices_impl<First, Step, N / 2>::type,
133 First + N / 2 * Step,
134 First + (N - 1) * Step
138template<
size_t First,
size_t Last,
size_t Step = 1>
143 ((Last - First) + (Step - 1)) / Step
147template <
size_t Start,
size_t Last,
size_t Step = 1 >
155inline namespace __ROOT {
159struct check_bound_t {};
160static constexpr check_bound_t check_bound{};
168 typedef T element_type;
169 typedef std::remove_cv<T> value_type;
170 typedef element_type * pointer;
171 typedef element_type
const* const_pointer;
172 typedef element_type & reference;
173 typedef element_type
const& const_reference;
174 typedef element_type * iterator;
175 typedef element_type
const* const_iterator;
176 typedef ptrdiff_t difference_type;
177 typedef std::size_t size_type;
178 typedef std::reverse_iterator<iterator> reverse_iterator;
179 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
184 constexpr span() noexcept
185 : length_(0), data_(
nullptr)
188 constexpr span(span
const&)
noexcept =
default;
189 constexpr span(span &&) noexcept = default;
193 template<size_type
N>
194 span(std::array<T,
N> &
a) noexcept
195 : length_(
N), data_(
N > 0 ?
a.data() :
nullptr)
200 template<
size_type N>
201 span(
T(&
a)[
N]) noexcept
202 : length_(
N), data_(
N > 0 ? std::addressof(
a[0]) : nullptr)
204 static_assert(
N > 0,
"Zero-length array is not permitted in ISO C++.");
207 span(std::vector<
typename std::remove_cv<T>::type>
const&
v) noexcept
208 : length_(
v.size()), data_(
v.empty() ?
nullptr :
v.
data())
211 span(std::vector<
typename std::remove_cv<T>::type> &
v) noexcept
212 : length_(
v.size()), data_(
v.empty() ?
nullptr :
v.
data())
215 constexpr span(pointer
a, size_type
const n) noexcept
216 : length_(
n), data_(
a)
221 class =
typename std::enable_if<
223 typename std::remove_cv<T>::type,
224 typename std::iterator_traits<InputIterator>::value_type
228 span(InputIterator start, InputIterator last)
229 : length_(std::distance(start, last)), data_(&*start)
232 span(std::initializer_list<T>
const&
l)
233 : length_(
l.
size()), data_(std::begin(
l))
236 span&
operator=(span
const&)
noexcept =
default;
237 span&
operator=(span &&) noexcept = delete;
242 constexpr iterator begin() const noexcept
246 constexpr iterator end() const noexcept
248 return data_ + length_;
250 constexpr const_iterator cbegin() const noexcept
254 constexpr const_iterator cend() const noexcept
258 reverse_iterator rbegin()
const
262 reverse_iterator rend()
const
266 const_reverse_iterator crbegin()
const
270 const_reverse_iterator crend()
const
278 constexpr size_type
size() const noexcept
282 constexpr size_type
length() const noexcept
286 constexpr size_type max_size() const noexcept
290 constexpr bool empty() const noexcept
294 constexpr reference operator[](size_type
const n)
const noexcept
298 constexpr reference at(size_type
const n)
const
303 return n >= length_ ?
throw std::out_of_range(
"span::at()") : *(data_ +
n);
305 constexpr pointer
data() const noexcept
309 constexpr const_reference front() const noexcept
313 constexpr const_reference back() const noexcept
315 return *(data_ + length_ - 1);
323 constexpr span<T> slice(check_bound_t, size_type
const pos, size_type
const slicelen)
const
330 return pos >= length_ || pos + slicelen >= length_ ?
throw std::out_of_range(
"span::slice()") : span<
T>{begin() + pos, begin() + pos + slicelen};
332 constexpr span<T> slice_before(check_bound_t, size_type
const pos)
const
339 return pos >= length_ ? std::out_of_range(
"span::slice()") : span<
T>{begin(), begin() + pos};
341 constexpr span<T> slice_after(check_bound_t, size_type
const pos)
const
348 return pos >= length_ ? std::out_of_range(
"span::slice()") : span<
T>{begin() + pos, end()};
352 constexpr span<T> slice(size_type
const pos, size_type
const slicelen)
const
354 return span<T>{begin() + pos, begin() + pos + slicelen};
356 constexpr span<T> slice_before(size_type
const pos)
const
358 return span<T>{begin(), begin() + pos};
360 constexpr span<T> slice_after(size_type
const pos)
const
362 return span<T>{begin() + pos, end()};
368 constexpr span<T> slice(check_bound_t, iterator start, iterator last)
const
378 return ( start >= end() ||
381 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};
383 constexpr span<T> slice_before(check_bound_t, iterator
const pos)
const
390 return pos < begin() || pos > end() ?
throw std::out_of_range(
"span::slice()") : span<
T>{begin(), pos > end() ? end() : pos};
392 constexpr span<T> slice_after(check_bound_t, iterator
const pos)
const
399 return pos < begin() || pos > end() ?
throw std::out_of_range(
"span::slice()") : span<
T>{pos < begin() ? begin() : pos, end()};
403 constexpr span<T> slice(iterator start, iterator last)
const
405 return span<T>{start, last};
407 constexpr span<T> slice_before(iterator
const pos)
const
409 return span<T>{begin(), pos};
411 constexpr span<T> slice_after(iterator
const pos)
const
413 return span<T>{pos, end()};
421 template<class Allocator = std::allocator<typename std::remove_cv<T>::type>>
422 auto to_vector(Allocator
const& alloc = Allocator{})
const
423 -> std::vector<
typename std::remove_cv<T>::type, Allocator>
425 return {begin(), end(), alloc};
429 auto to_array() const
435 template<
size_t...
I>
437 -> std::array<
T,
sizeof...(I)>
439 return {{(
I < length_ ? *(data_ +
I) :
T{} )...}};
454template<
class ArrayL,
class ArrayR >
456bool operator_equal_impl(ArrayL
const& lhs,
size_t const lhs_size, ArrayR
const& rhs,
size_t const rhs_size)
458 if (lhs_size != rhs_size) {
462 auto litr = std::begin(lhs);
463 auto ritr = std::begin(rhs);
464 for (; litr != std::end(lhs); ++litr, ++ritr) {
465 if (!(*litr == *ritr)) {
476inline namespace __ROOT {
478template<
class T1,
class T2>
480bool operator==(span<T1>
const& lhs, span<T2>
const& rhs)
488 class =
typename std::enable_if<
493bool operator==(span<T>
const& lhs, Array
const& rhs)
498template<
class T1,
class T2,
size_t N>
508 class =
typename std::enable_if<
509 is_array<Array>::value
513bool operator!=(span<T>
const& lhs, Array
const& rhs)
515 return !(lhs == rhs);
521 class =
typename std::enable_if<
522 is_array<Array>::value
526bool operator==(Array
const& lhs, span<T>
const& rhs)
534 class =
typename std::enable_if<
535 is_array<Array>::value,
540bool operator!=(Array
const& lhs, span<T>
const& rhs)
542 return !(rhs == lhs);
549 class =
typename std::enable_if<
554auto make_view(Array
const&
a)
555-> span<typename Array::value_type>
560template<
class T,
size_t N>
562span<T> make_view(T
const (&
a)[
N])
569span<T> make_view(T
const*
p,
typename span<T>::size_type
const n)
571 return span<T>{
p,
n};
574template<class InputIterator, class Result = span<typename std::iterator_traits<InputIterator>::value_type>>
576Result make_view(InputIterator begin, InputIterator end)
578 return Result{begin, end};
583span<T> make_view(std::initializer_list<T>
const&
l)
601#include <type_traits>
613 static constexpr int rank = Rank;
614 using reference = ptrdiff_t &;
615 using const_reference =
const ptrdiff_t &;
616 using size_type = size_t;
617 using value_type = ptrdiff_t;
620 std::array<value_type, Rank> m_B;
623 constexpr bounds() noexcept;
625 constexpr bounds(value_type
b) noexcept: m_B{{
b}} { };
630 reference operator[](size_type i)
noexcept {
return m_B[i]; }
632 constexpr const_reference operator[](
633 size_type i)
const noexcept {
return m_B[i]; };
636 bool operator==(
const bounds &rhs)
const noexcept;
638 bool operator!=(
const bounds &rhs)
const noexcept;
640 bounds
operator+(
const index<rank> &rhs)
const noexcept;
642 bounds
operator-(
const index<rank> &rhs)
const noexcept;
644 bounds &
operator+=(
const index<rank> &rhs)
noexcept;
646 bounds &
operator-=(
const index<rank> &rhs)
noexcept;
648 constexpr size_type
size() const noexcept;
650 bool contains(const
index<rank> &idx) const noexcept;
661 static constexpr int rank = Rank;
662 using reference = ptrdiff_t &;
663 using const_reference =
const ptrdiff_t &;
664 using size_type = size_t;
665 using value_type = ptrdiff_t;
668 constexpr index() noexcept;
670 constexpr
index(value_type) noexcept;
672 constexpr
index(const initializer_list<value_type> &) noexcept;
678 reference operator[](size_type component_idx) noexcept;
680 constexpr const_reference operator[](size_type component_idx) const noexcept;
682 bool operator==(const
index &rhs) const noexcept;
684 bool operator!=(const
index &rhs) const noexcept;
686 index operator+(const
index &rhs) const noexcept;
688 index operator-(const
index &rhs) const noexcept;
694 index &operator++() noexcept;
696 index operator++(
int) noexcept;
698 index &operator--() noexcept;
700 index operator--(
int) noexcept;
702 index operator+() const noexcept;
704 index operator-() const noexcept;
709template<typename ValueType,
int Rank = 1>
712 static constexpr int rank = Rank;
713 using size_type = index<rank>;
714 using bounds_type = bounds<rank>;
715 using size_type =
typename bounds_type::size_type;
716 using value_type = ValueType;
717 using pointer =
typename std::add_pointer_t<value_type>;
718 using reference =
typename std::add_lvalue_reference_t<value_type>;
720 constexpr span() noexcept;
722 constexpr explicit span(std::vector<ValueType> &cont) noexcept;
724 template<typename ArrayType>
725 constexpr explicit span(ArrayType &
data) noexcept;
727 template<typename ViewValueType>
728 constexpr span(const span<ViewValueType, rank> &rhs) noexcept;
730 template<typename Container>
731 constexpr span(bounds_type bounds, Container &cont) noexcept;
733 constexpr span(bounds_type bounds, pointer
data) noexcept;
735 template<typename ViewValueType>
736 span &operator=(const span<ViewValueType, rank> &rhs) noexcept;
738 constexpr bounds_type bounds() const noexcept;
739 constexpr size_type
size() const noexcept;
740 constexpr size_type stride() const noexcept;
742 constexpr pointer
data() const noexcept;
743 constexpr reference operator[](const size_type& idx) const noexcept;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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)
RVec< T0 > & operator-=(RVec< T0 > &v, const T1 &y)
typename make_indices_< Start, Last, Step >::type make_indices
bool operator_equal_impl(ArrayL const &lhs, size_t const lhs_size, ArrayR const &rhs, size_t const rhs_size)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
#define R__CONSTEXPR_IF_CXX14
static constexpr size_t value[sizeof...(Indices)]