tinympl  0.2
mini MPL library for C++11
insert.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_INSERT_HPP
14 #define TINYMPL_VARIADIC_INSERT_HPP
15 
16 #include <cstddef>
17 
18 namespace tinympl {
19 namespace variadic {
20 
30 template<std::size_t pos,class T,template<class ... > class Out,class ... Args> struct insert;
31 
32 template<std::size_t pos,class T,template<class ... > class Out,class Head,class ... Args> struct insert<pos,T,Out,Head,Args...>
33 {
34 private:
35  template<class ... CopiedElements>
36  struct impl
37  {
38  typedef typename insert<pos-1,T,Out,Args...>::template impl<CopiedElements...,Head>::type type;
39  };
40 
41  template<std::size_t,class,template<class ... > class,class ...> friend struct insert;
42 
43 public:
44  static_assert(pos <= sizeof ... (Args) + 1,"pos > sequence size!");
45 
46  typedef typename impl<>::type type;
47 };
48 
49 template<class T,template<class ... > class Out,class Head,class ... Args> struct insert<0,T,Out,Head,Args...>
50 {
51 private:
52  template<class ... CopiedElements>
53  struct impl
54  {
55  typedef Out< CopiedElements ..., T, Head,Args ... > type;
56  };
57 
58  template<std::size_t,class,template<class ... > class,class ...> friend struct insert;
59 
60 public:
61  typedef typename impl<>::type type;
62 };
63 
64 template<class T,template<class ... > class Out> struct insert<0,T,Out>
65 {
66 private:
67  template<class ... CopiedElements>
68  struct impl
69  {
70  typedef Out< CopiedElements ..., T > type;
71  };
72 
73  template<std::size_t,class,template<class ... > class,class ...> friend struct insert;
74 
75 public:
76  typedef typename impl<>::type type;
77 };
78 
79 } // namespace variadic
80 } // namespace tinympl
81 
82 #endif // TINYMPL_VARIADIC_INSERT_HPP
Produce an output sequence from a variadic template inserting a new element at a given position...
Definition: insert.hpp:30
Insert a subsequence into a given sequence at a given position.
Definition: insert.hpp:36