NiHu  2.0
vector.hpp
Go to the documentation of this file.
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
24 #ifndef VECTOR_HPP_INCLUDED
25 #define VECTOR_HPP_INCLUDED
26 
27 #include "integer.hpp"
28 #include "sequence.hpp"
29 
30 #include <tuple>
31 
32 namespace tmp
33 {
35  struct vector_tag;
36 
41  template <class...Args>
42  struct vector
43  {
45  typedef vector type;
47  typedef vector_tag tag;
48 
50  typedef std::tuple<Args...> impl;
51  };
52 
53  namespace internal
54  {
55  template <>
56  struct empty_impl<vector_tag> : vector<> {};
57 
58  template <>
59  struct at_impl<vector_tag>
60  {
61  template <class Seq, class Pos>
62  struct apply : std::tuple_element<Pos::value, typename Seq::impl> {};
63  };
64  } // namespace internal
65 
67  template <class Seq, class Pos>
69  {
72  };
73 
75  template <class Seq, class Pos>
76  struct next<vector_iterator<Seq, Pos> > :
77  vector_iterator<Seq, typename next<Pos>::type> {};
78 
80  template <class Seq, class Pos>
81  struct prev<vector_iterator<Seq, Pos> > :
82  vector_iterator<Seq, typename prev<Pos>::type> {};
83 
84  namespace internal
85  {
86  template <>
87  struct size_impl<vector_tag>
88  {
89  template <class Seq>
90  struct apply : integer<int, std::tuple_size<typename Seq::impl>::value> {};
91  };
92  }
93 
95  template <class Seq, class Pos>
96  struct deref<vector_iterator<Seq, Pos> > : at<Seq, Pos> {};
97 
98  namespace internal
99  {
100  template <>
101  struct begin_impl<vector_tag>
102  {
103  template <class Vect>
104  struct apply
105  {
107  };
108  };
109 
110  template <>
111  struct end_impl<vector_tag>
112  {
113  template <class Vect>
114  struct apply
115  {
116  typedef vector_iterator<
117  Vect,
118  typename size_impl<vector_tag>::template apply<Vect>::type
119  > type;
120  };
121  };
122 
123  template <>
124  struct clear_impl<vector_tag>
125  {
126  template <class Seq>
127  struct apply : vector<> {};
128  };
129 
131  template <class Vect, class T>
132  struct vector_push_front;
133 
134  template <class...Args, class T>
135  struct vector_push_front<vector<Args...>, T> : vector<T, Args...> {};
136 
137  template <>
138  struct push_front_impl<vector_tag>
139  {
140  template <class Vect, class T>
141  struct apply : vector_push_front<Vect, T> {};
142  };
143 
145  template <class Vect, class T>
146  struct vector_push_back;
147 
148  template <class...Args, class T>
149  struct vector_push_back<vector<Args...>, T> : vector<Args..., T> {};
150 
151  template <>
152  struct push_back_impl<vector_tag>
153  {
154  template <class Seq, class T>
155  struct apply : vector_push_back<Seq, T> {};
156  };
157 
158 
160  template <class Vect>
161  struct vector_pop_front;
162 
163  template <class...Args, class T>
164  struct vector_pop_front<vector<T, Args...> > : vector<Args...> {};
165 
166  template <>
167  struct pop_front_impl<vector_tag>
168  {
169  template <class Seq>
170  struct apply : vector_pop_front<Seq> {};
171  };
172 
173  } // namespace internal
174 } // namespace tmp
175 
176 #endif /* VECTOR_HPP_INCLUDED */
177 
tmp::vector_iterator
the vector iterator type used by tmp::begin, tmp::end and tmp::deref
Definition: vector.hpp:68
tmp::integer
integer type representation
Definition: integer.hpp:54
tmp::deref
metafunction to dereference an iterator
Definition: sequence.hpp:114
tmp
template metaprogramming functions
Definition: asymptotic_types.hpp:101
tmp::vector
Compile time vector with an arbitrary number of arguments.
Definition: vector.hpp:42
tmp::prev
decrement operator
Definition: operator.hpp:39
tmp::vector::type
vector type
self returning
Definition: vector.hpp:45
integer.hpp
integer type representation and basic integer arithmetics
tmp::vector::impl
std::tuple< Args... > impl
the underlying std::tuple container
Definition: vector.hpp:50
tmp::apply
The apply metafunction shortcut for lambda evaluation.
Definition: lambda.hpp:239
sequence.hpp
implementation of compile time sequences
tmp::vector_iterator::type
vector_iterator type
self-returning matafunction
Definition: vector.hpp:71
tmp::next
increment operator
Definition: operator.hpp:35
tmp::at
return element at a given position
Definition: sequence.hpp:74
tmp::vector::tag
vector_tag tag
the tag for algorithm selection
Definition: vector.hpp:47