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_INSERT_HPP
14 #define TINYMPL_INSERT_HPP
15 
16 #include <tinympl/variadic/erase.hpp>
17 #include <tinympl/as_sequence.hpp>
18 #include <tinympl/sequence.hpp>
19 #include <tinympl/join.hpp>
20 
21 namespace tinympl {
22 
32 template < std::size_t Pos,
33  class SubSeq,
34  class Seq,
35  template<class ...> class Out = as_sequence<Seq>::template rebind>
36 struct insert : insert<Pos, as_sequence_t<SubSeq>, as_sequence_t<Seq>, Out> {};
37 
38 template< std::size_t Pos, class ... SubSeqArgs, class ... SeqArgs,
39 template<class...> class Out>
40 class insert<Pos, sequence<SubSeqArgs...>, sequence<SeqArgs...>, Out> {
41  template<class ... Us>
42  using head_seq = sequence<Us ..., SubSeqArgs ... >;
43 
44  typedef typename variadic::erase<Pos, sizeof ...( SeqArgs ), head_seq,
45 SeqArgs ... >::type head;
46  typedef typename variadic::erase<0, Pos, sequence, SeqArgs ... >::type tail;
47 
48 public:
49  typedef typename join<Out<>, head, tail>::type type;
50 };
51 
52 } // namespace tinympl
53 
54 #endif // TINYMPL_INSERT_HPP
Merge two sequences.
Definition: join.hpp:29
The main sequence type.
Definition: sequence.hpp:28
Produce an output sequence from a variadic template by removin the elements in the given range...
Definition: erase.hpp:30
Insert a subsequence into a given sequence at a given position.
Definition: insert.hpp:36