tinympl  0.2
mini MPL library for C++11
vector.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_VECTOR_HPP
14 #define TINYMPL_VECTOR_HPP
15 
16 #include <tinympl/algorithm.hpp>
17 #include <tinympl/sequence.hpp>
18 
19 namespace tinympl {
20 
33 template<class ... Args>
34 struct vector
35 {
36  enum
37  {
38  size = sizeof ... (Args)
39  };
40 
41  enum
42  {
43  empty = (size == 0)
44  };
45 
47  template<std::size_t i>
48  struct at
49  {
50  static_assert(i < size,"Index i is out of range");
51  typedef typename variadic::at<i,Args...>::type type;
52  };
53 
55  template<class T>
56  struct push_back
57  {
58  typedef vector<Args...,T> type;
59  };
60 
62  template<class T>
63  struct push_front
64  {
65  typedef vector<T,Args...> type;
66  };
67 
69  struct pop_back
70  {
71  typedef typename variadic::erase<size-1,size,tinympl::vector,Args...>::type type;
72  };
73 
75  struct pop_front
76  {
77  typedef typename variadic::erase<0,1,tinympl::vector,Args...>::type type;
78  };
79 
81  template<std::size_t first,std::size_t last>
82  struct erase : tinympl::erase<first,last,vector<Args...>,tinympl::vector> {};
83 
85  template<std::size_t i,class ... Ts>
86  struct insert : tinympl::insert<i,
87  sequence<Ts...>,
88  vector<Args...>,
89  tinympl::vector> {};
90 
92  struct front
93  {
94  typedef typename variadic::at<0,Args...>::type type;
95  };
96 
98  struct back
99  {
100  typedef typename variadic::at<size-1,Args...>::type type;
101  };
102 };
103 
110 template<class ... Args> struct as_sequence<vector<Args...> >
111 {
112  typedef sequence<Args...> type;
113  template<class ... Ts> using rebind = vector<Ts...>;
114 };
115 
116 }
117 
118 #endif // TINYMPL_VECTOR_HPP
Provide a customization points by allowing the user to specialize this class.
Definition: as_sequence.hpp:30
Extract the i-th element of a variadic template.
Definition: at.hpp:27
The size of the vector.
Definition: vector.hpp:38
Return a new vector constructed by inserting T on the front of the current vector.
Definition: vector.hpp:63
Access the i-th element.
Definition: vector.hpp:48
Return a new vector constructed by inserting the elements Ts... in the current vector starting at the...
Definition: vector.hpp:86
Get the number of elements of a sequence.
Definition: size.hpp:27
Return the last element of the vector.
Definition: vector.hpp:98
Return a new vector constructed by erasing the elements in the range [first,last) of the current vect...
Definition: vector.hpp:82
Return the first element of the vector.
Definition: vector.hpp:92
Return a new vector constructed by removing the first element of the current vector.
Definition: vector.hpp:75
Return a new vector constructed by inserting T on the back of the current vector. ...
Definition: vector.hpp:56
Determine whether the vector is empty.
Definition: vector.hpp:43
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
A compile time vector of types Vector is the simplest tinympl sequence type. It provides standard mod...
Definition: vector.hpp:34
Return a new vector constructed by removing the last element of the current vector.
Definition: vector.hpp:69
Remove a range in a given sequence.
Definition: erase.hpp:35