SUNphi  1.0
IntSeqTranspose.hpp
Go to the documentation of this file.
1 #ifndef _INTSEQTRANSPOSE_HPP
2 #define _INTSEQTRANSPOSE_HPP
3 
4 /// \file IntSeqTranspose.hpp
5 ///
6 /// \brief Transpose a \c Tuple of \c IntSeq
7 
8 #include <ints/IntSeq.hpp>
9 #include <ints/Ranges.hpp>
10 #include <tuple/TupleClass.hpp>
11 
12 namespace SUNphi
13 {
14  /// Slice a list of \c IntSeq according to a position
15  ///
16  /// Internal implementation performing checks and getting the \c
17  /// IntSeq list out of the \c Tuple
18  template<int Sl, // Slice to get
19  typename...Is> // List of IntSeq to slice
20  DECLAUTO _IntSeqsSlice(Tuple<Is...> tupleOfIntSeqs)
21  {
22  static_assert(Sl>=0 and ((Sl<Is::size) && ...),"Sl must be between 0 and the maximal size of the IntSeq");
23 
24  return IntSeq<Is::template element<Sl>()...>{};
25  }
26 
27  /// Slice a list of \c IntSeq according to a position
28  ///
29  /// Gives visibility to the internal implementation
30  template<int Sl, // Slice to get
31  typename Tp> // \c Tuple of \c IntSeq to slice
32  using IntSeqsSlice=
33  decltype(_IntSeqsSlice<Sl>(Tp{}));
34 
35  /////////////////////////////////////////////////////////////////
36 
37  /// Slice a list of \c IntSeq according to a list of positions
38  ///
39  /// Internal implementation getting the list of slices out of the \c
40  /// IntSeq, as well as the \c IntSeq out of the \c Tuple
41  template<int...Sl, // List of slices
42  typename...Is> // List of \c IntSeq
43  DECLAUTO _IntSeqsSlices(IntSeq<Sl...> listOfSlices,
44  Tuple<Is...> tupleOfIntSeqs)
45  {
46  /// Returned type
47  using Ret=
48  Tuple<IntSeqsSlice<Sl,Tuple<Is...>>...>;
49 
50  return Ret{};
51  }
52 
53  /////////////////////////////////////////////////////////////////
54 
55  /// Transpose a list of \c IntSeq
56  ///
57  /// Internal implementation checking that all \c IntSeq have the
58  /// same size and that the \c Tuple is not empty
59  template<typename...Is> // List of \c IntSeq
60  DECLAUTO _IntSeqsTranspose(Tuple<Is...> tupleOfIntSeqs)
61  {
62  if constexpr(sizeof...(Is)!=0)
63  {
64  /// \c Tuple of \c IntSeq type
65  using Tp=
66  Tuple<Is...>;
67 
68  /// Size of 0-th \c IntSeq
69  constexpr int size0=
70  TupleElementType<0,Tp>::size;
71 
72  // Check that all \c IntSeq have the same size
73  static_assert(((Is::size==size0) && ...),"All IntSeq must have ths same size");
74 
75  /// Returned type
76  using Res=
77  decltype(_IntSeqsSlices(IntsUpTo<size0>{},
78  Tp{}));
79 
80  return Res{};
81  }
82  else
83  return Tuple<>{};
84  }
85 
86  /// Transpose a list of \c IntSeq
87  ///
88  /// Gives visibility to the internal implementation
89  template<typename Tp>
90  using IntSeqsTranspose=
91  decltype(_IntSeqsTranspose(Tp{}));
92 }
93 
94 #endif
decltype(auto) _IntSeqsSlice(Tuple< Is... > tupleOfIntSeqs)
#define DECLAUTO
Short name for decltype(auto)