IndexSeq.hpp 1022 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

// from http://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence/17426611#17426611
namespace AMDiS
{
  template <size_t...> struct Seq {};

  namespace detail
  {
    template <size_t s, class S>
    struct Concat;

    template <size_t s, size_t ... i>
    struct Concat<s, Seq<i... >>
    {
      using type = Seq<i..., (s + i)... >;
    };

    template <bool, class S>
    struct IncSeq_if 
    { 
      using type = S; 
    };

    template <size_t... Is>
    struct IncSeq_if<true, Seq<Is...>>
    {
      using type = Seq<Is..., sizeof...(Is)>;
    };
    
  } // end namespace detail
  
  template <size_t N>
  struct MakeSeq 
  {
    using type = typename detail::IncSeq_if< (N % 2 != 0), 
      typename detail::Concat<N/2, typename MakeSeq<N/2>::type>::type >::type;
  };

  // break condition
  template <> struct MakeSeq<0> { using type = Seq<>; };

  // alias template
  template <size_t N>
  using MakeSeq_t = typename MakeSeq<N>::type;
  
} // end namespace AMDiS