PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/prelude/tlists.hpp

http://github.com/Eelis/geordi
C++ Header | 38 lines | 25 code | 12 blank | 1 comment | 0 complexity | 0111ea785bd8ccf7651bfe90d55e7a09 MD5 | raw file
 1#ifndef TLISTS_HPP
 2#define TLISTS_HPP
 3
 4#include <string>
 5
 6namespace tlists
 7{
 8  template <typename...> struct tlist;
 9
10  template <typename H, typename T> struct cons;
11  template <typename H, typename... T> struct cons<H, tlist<T...> > { typedef tlist<H, T...> type; };
12
13  template <size_t, typename> struct group;
14
15  // group_successive
16
17  template <typename, size_t, typename...> struct group_successive_impl;
18
19  template <typename A, typename B, typename... T>
20  struct group_successive_impl<A, 0, B, T...>
21  { typedef typename group_successive_impl<B, 1, T...>::type type; };
22
23  template <typename A, size_t N, typename... T>
24  struct group_successive_impl<A, N, A, T...>
25  { typedef typename group_successive_impl<A, N + 1, T...>::type type; };
26
27  template <typename A, size_t N, typename B, typename... T>
28  struct group_successive_impl<A, N, B, T...>
29  { typedef typename cons<group<N, A>, typename group_successive_impl<B, 1, T...>::type>::type type; };
30
31  template <typename A> struct group_successive_impl<A, 0> { typedef tlist<> type; };
32  template <typename A, size_t N> struct group_successive_impl<A, N>
33  { typedef tlist<group<N, A> > type; };
34
35  template <typename... T> struct group_successive: group_successive_impl<void, 0, T...> {};
36}
37
38#endif // header guard