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 32 #include <type_traits> 34 #include <initializer_list> 43 static bool const value =
false;
45 template<
class T,
size_t N>
60 template<
size_t... Indices >
62 static constexpr
size_t value[
sizeof...(Indices)] = {Indices...};
65 template<
class IndicesType,
size_t Next>
68 template<
size_t... Indices,
size_t Next>
73 template<
class IndicesType,
size_t Next,
size_t Tail>
76 template<
size_t... Indices,
size_t Next,
size_t Tail>
81 template<
size_t First,
size_t Step,
size_t N,
class =
void>
84 template<
size_t First,
size_t Step,
size_t N>
94 template<
size_t First,
size_t Step,
size_t N>
104 template<
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,
117 template<
size_t First,
size_t Step,
size_t N>
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
131 template<
size_t First,
size_t Last,
size_t Step = 1>
136 ((Last - First) + (Step - 1)) / Step
140 template <
size_t Start,
size_t Last,
size_t Step = 1 >
148 inline namespace __ROOT {
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>
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))
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
250 const_reverse_iterator
rend()
const 258 const_reverse_iterator
crend()
const 266 constexpr size_type
size() const noexcept
270 constexpr size_type
length() 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);
318 return pos >= length_ || pos + slicelen >= length_ ?
throw std::out_of_range(
"span::slice()") :
span<T>{begin() + pos, begin() + pos + slicelen};
327 return pos >= length_ ? std::out_of_range(
"span::slice()") :
span<T>{begin(), begin() + pos};
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};
346 return span<T>{begin(), begin() + pos};
350 return span<T>{begin() + pos, end()};
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};
378 return pos < begin() || pos > end() ?
throw std::out_of_range(
"span::slice()") :
span<T>{begin(), pos > end() ? end() : pos};
387 return pos < begin() || pos > end() ?
throw std::out_of_range(
"span::slice()") :
span<T>{pos < begin() ? begin() : 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};
423 template<
size_t...
I>
425 -> std::array<
T,
sizeof...(I)>
427 return {{(
I < length_ ? *(data_ +
I) : T{} )...}};
442 template<
class ArrayL,
class ArrayR >
444 bool 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)) {
464 inline namespace __ROOT {
466 template<
class T1,
class T2>
476 class =
typename std::enable_if<
486 template<
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<
548 template<
class T,
size_t N>
562 template<class InputIterator, class Result = span<typename std::iterator_traits<InputIterator>::value_type>>
564 Result
make_view(InputIterator begin, InputIterator end)
566 return Result{begin, end};
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;
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;
697 template<
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>
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>
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;
735 #endif // too complex! constexpr const_iterator cend() const noexcept
value_type const * iterator
constexpr const_reference front() const noexcept
constexpr const_iterator end() const noexcept
constexpr size_type max_size() const noexcept
constexpr span< T > slice_after(check_bound_t, size_type const pos) const
Namespace for new ROOT classes and functions.
span(InputIterator start, InputIterator last)
constexpr const_reference operator[](size_type const n) const noexcept
ptrdiff_t difference_type
constexpr span< T > slice(check_bound_t, iterator start, iterator last) const
constexpr size_type size() const noexcept
constexpr span< T > slice_after(size_type const pos) const
const_reverse_iterator crend() const
span(std::vector< T > const &v) noexcept
constexpr span< T > slice_after(check_bound_t, iterator const pos) const
static constexpr check_bound_t check_bound
void Step(const gsl_rng *r, void *xp, double step_size)
constexpr span< T > slice_after(iterator const pos) const
const_pointer const data_
constexpr span< T > slice_before(check_bound_t, iterator const pos) const
constexpr size_type length() const noexcept
constexpr span() noexcept
constexpr bool empty() const noexcept
typename make_indices_< Start, Last, Step >::type make_indices
R__CONSTEXPR_IF_CXX14 bool operator_equal_impl(ArrayL const &lhs, size_t const lhs_size, ArrayR const &rhs, size_t const rhs_size)
std::reverse_iterator< const_iterator > const_reverse_iterator
auto to_vector(Allocator const &alloc=Allocator{}) const -> std::vector< T, Allocator >
TTime operator-(const TTime &t1, const TTime &t2)
#define R__CONSTEXPR_IF_CXX14
constexpr span< T > slice_before(check_bound_t, size_type const pos) const
constexpr bool operator==(Array const &lhs, span< T > const &rhs)
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
constexpr const_pointer data() const noexcept
value_type const & reference
value_type const * const_iterator
constexpr span< T > slice(size_type const pos, size_type const slicelen) const
constexpr span(T const *a, size_type const n) noexcept
constexpr span< T > slice_before(iterator const pos) const
constexpr const_iterator begin() const noexcept
span(std::array< T, N > const &a) noexcept
auto to_array() const -> std::array< T, N >
const_reverse_iterator crbegin() const
value_type const & const_reference
constexpr span< T > make_view(std::initializer_list< T > const &l)
constexpr const_reference at(size_type const n) const
Binding & operator=(OUT(*fun)(void))
value_type const * pointer
const_reverse_iterator rend() const
std::reverse_iterator< iterator > reverse_iterator
constexpr span< T > slice_before(size_type const pos) const
constexpr const_reference back() const noexcept
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
constexpr bool operator!=(Array const &lhs, span< T > const &rhs)
constexpr span< T > slice(iterator start, iterator last) const
span(T const (&a)[N]) noexcept
constexpr const_iterator cbegin() const noexcept
constexpr span< T > slice(check_bound_t, size_type const pos, size_type const slicelen) const
auto to_array_impl(ROOT::Detail::indices< I... >) const -> std::array< T, sizeof...(I)>
value_type const * const_pointer
span(std::initializer_list< T > const &l)
const_reverse_iterator rbegin() const
std::string & operator+=(std::string &left, const TString &right)