Logo ROOT   6.14/05
Reference Guide
RIntegerSequence.hxx
Go to the documentation of this file.
1 /// \file ROOT/RIntegerSequence.hxx
2 /// \ingroup Base StdExt
3 /// \author Enrico Guiraud <enrico.guiraud@cern.ch>
4 /// \date 2018-04-06
5 
6 /*************************************************************************
7  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
8  * All rights reserved. *
9  * *
10  * For the licensing terms see $ROOTSYS/LICENSE. *
11  * For the list of contributors see $ROOTSYS/README/CREDITS. *
12  *************************************************************************/
13 
14 #ifndef ROOT_RIntegerSequence
15 #define ROOT_RIntegerSequence
16 
17 #include <RConfigure.h>
18 #include "ROOT/RSpan.hxx"
19 
20 #ifdef R__HAS_STD_INDEX_SEQUENCE
21 // no need to backport
22 
23 #include <utility>
24 
25 #else
26 // backport libc++'s implementation (master branch, commit ece1de8)
27 
28 #include <cstddef>
29 #include <type_traits>
30 
31 namespace ROOT {
32 namespace Detail {
33 
34 template <class _IdxType, _IdxType... _Values>
36  template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
37  using __convert = _ToIndexSeq<_ToIndexType, _Values...>;
38 };
39 
40 template<typename _Tp, size_t ..._Extra>
41 struct __repeat;
42 
43 template<typename _Tp, _Tp ..._Np, size_t ..._Extra>
44 struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
45  typedef __integer_sequence<_Tp,
46  _Np...,
47  sizeof...(_Np) + _Np...,
48  2 * sizeof...(_Np) + _Np...,
49  3 * sizeof...(_Np) + _Np...,
50  4 * sizeof...(_Np) + _Np...,
51  5 * sizeof...(_Np) + _Np...,
52  6 * sizeof...(_Np) + _Np...,
53  7 * sizeof...(_Np) + _Np...,
54  _Extra...> type;
55 };
56 
57 template<size_t _Np> struct __parity;
58 template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
59 
60 template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
61 template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
62 template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
63 template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; };
64 template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; };
65 template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
66 template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
68 
69 template <>
70 struct __parity<0> {
71  template <size_t _Np>
72  struct __pmake : __repeat<typename __make<_Np / 8>::type> {
73  };
74 };
75 template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
76 template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
77 template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
78 template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
79 template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
80 template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
81 template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
82 
83 } // namespace Detail
84 } // namespace ROOT
85 
86 namespace std {
87 
88 template <class _Tp, _Tp... _Ip>
90  typedef _Tp value_type;
91  static_assert(is_integral<_Tp>::value, "std::integer_sequence can only be instantiated with an integral type");
92  static constexpr size_t size() noexcept { return sizeof...(_Ip); }
93 };
94 
95 template <size_t... _Ip>
96 using index_sequence = integer_sequence<size_t, _Ip...>;
97 
98 template <typename _Tp, _Tp _Np>
100  typename ROOT::Detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
101 
102 template <class _Tp, _Tp _Ep>
104  static_assert(is_integral<_Tp>::value, "std::make_integer_sequence can only be instantiated with an integral type");
105  static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
106  // Workaround GCC bug by preventing bad installations when 0 <= _Ep
107  // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
109 };
110 
111 template <class _Tp, _Tp _Ep>
113 
114 template <class _Tp, _Tp _Np>
116 
117 template <size_t _Np>
119 
120 template <class... _Tp>
121 using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
122 
123 } // namespace std
124 
125 #endif // R__HAS_STD_INDEX_SEQUENCE
126 #endif // ROOT_RIntegerSequence
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
__make_integer_sequence< _Tp, _Np > make_integer_sequence
__integer_sequence< size_t, 0, 1, 2, 3, 4, 5 > type
typename __make_integer_sequence_checked< _Tp, _Ep >::type __make_integer_sequence
__integer_sequence< size_t, 0, 1, 2 > type
STL namespace.
static constexpr size_t size() noexcept
__integer_sequence< size_t, 0, 1, 2, 3, 4 > type
__integer_sequence< size_t > type
__integer_sequence< size_t, 0, 1, 2, 3 > type
__integer_sequence< size_t, 0 > type
int type
Definition: TGX11.cxx:120
make_index_sequence< sizeof...(_Tp)> index_sequence_for
typename ROOT::Detail::__make< _Np >::type::template __convert< integer_sequence, _Tp > __make_integer_sequence_unchecked
__integer_sequence< size_t, 0, 1 > type
__integer_sequence< size_t, 0, 1, 2, 3, 4, 5, 6 > type
make_integer_sequence< size_t, _Np > make_index_sequence
_ToIndexSeq< _ToIndexType, _Values... > __convert