tinympl  0.2
mini MPL library for C++11
generate_n.hpp
1 // Copyright (C) 2013, Ennio Barbaro.
2 //
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://sbabbi.github.io/tinympl for documentation.
8 //
9 // You are welcome to contact the author at:
10 // enniobarbaro@gmail.com
11 //
12 
13 #ifndef TINYMPL_VARIADIC_GENERATE_N_HPP
14 #define TINYMPL_VARIADIC_GENERATE_N_HPP
15 
16 #include <type_traits>
17 #include <cstddef>
18 
19 namespace tinympl {
20 namespace variadic {
21 
35 template<std::size_t n,
36  template<class ...> class Gen,
37  template<class ...> class Out> struct generate_n;
38 
39 template< std::size_t n, template<class ...> class Gen, template<class ...>
40 class Out>
41 struct generate_n {
42 private:
43  template<int i, class ... Ts>
44  struct impl {
45  typedef typename Gen< std::integral_constant<int, i> >::type new_type;
46  typedef typename generate_n < n - 1, Gen, Out >::
47  template impl < i + 1, Ts..., new_type >::type type;
48  };
49 
50  template<std::size_t, template<class ...> class, template<class ...> class>
51  friend struct generate_n;
52 
53 public:
54  typedef typename impl<0>::type type;
55 };
56 
57 template< template<class ...> class Gen, template<class ...> class Out>
58 struct generate_n<0, Gen, Out> {
59 private:
60  template<int i, class ... Ts>
61  struct impl {
62  typedef Out<Ts...> type;
63  };
64 
65  template<std::size_t, template<class ...> class, template<class ...> class>
66  friend struct generate_n;
67 
68 public:
69  typedef typename impl<0>::type type;
70 };
71 
72 } // namespace variadic
73 } // namespace tinympl
74 
75 #endif // TINYMPL_VARIADIC_GENERATE_N_HPP
Generate n elements using a given generator metafunction.
Definition: generate_n.hpp:37
Generate N elements using a given generator metafunction.
Definition: generate_n.hpp:36