All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
types_vector.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
23 #ifndef PAAL_TYPES_VECTOR_HPP
24 #define PAAL_TYPES_VECTOR_HPP
25 
26 #include <type_traits>
27 
28 namespace paal {
29 namespace data_structures {
30 
32 template <typename... Args> struct TypesVector;
33 
35 template <typename Vec> struct size;
36 
38 template <typename... Args> struct size<TypesVector<Args...>> {
39  enum {
40  value = sizeof...(Args)
41  };
42 };
43 
45 template <typename Vector, typename StartValue, typename Functor> struct fold;
46 
48 template <typename StartValue, typename Functor, typename Arg, typename... Args>
49 struct fold<TypesVector<Arg, Args...>, StartValue, Functor> {
50  typedef typename fold<
51  TypesVector<Args...>,
52  typename Functor::template apply<StartValue, Arg>::type, Functor>::type
53  type;
54 };
55 
57 template <typename StartValue, typename Functor>
58 struct fold<TypesVector<>, StartValue, Functor> {
59  typedef StartValue type;
60 };
61 
63 template <typename Vector, typename Val> struct push_back;
64 
66 template <typename Val, typename... Args>
67 struct push_back<TypesVector<Args...>, Val> {
68  typedef TypesVector<Args..., Val> type;
69 };
70 
72 template <typename Vector, typename Id> struct at;
73 
75 template <typename C, C i, typename Arg, typename... Args>
76 struct at<TypesVector<Arg, Args...>, std::integral_constant<C, i>> {
77  typedef typename at<Args..., std::integral_constant<C, i - 1>>::type type;
78 };
79 
81 template <typename C, typename Arg, typename... Args>
82 struct at<TypesVector<Arg, Args...>, std::integral_constant<C, 0>> {
83  typedef Arg type;
84 };
85 
87 template <typename V1, typename V2> struct join;
88 
90 template <typename... Args1, typename... Args2>
91 struct join<TypesVector<Args1...>, TypesVector<Args2...>> {
92  typedef TypesVector<Args1..., Args2...> type;
93 };
94 
96 template <int n, typename V> struct remove_n_first;
97 
99 template <int n, typename Arg, typename... Args>
100 struct remove_n_first<n, TypesVector<Arg, Args...>> {
101  typedef typename remove_n_first<n - 1, TypesVector<Args...>>::type type;
102 };
103 
105 template <typename Arg, typename... Args>
106 struct remove_n_first<0, TypesVector<Arg, Args...>> {
107  typedef TypesVector<Arg, Args...> type;
108 };
109 
111 template <> struct remove_n_first<0, TypesVector<>> {
112  typedef TypesVector<> type;
113 };
114 
116 template <typename Type, typename TypesVector> struct pos;
117 
119 template <typename Type, typename TypesPrefix, typename... TypesSufix>
120 struct pos<Type, TypesVector<TypesPrefix, TypesSufix...>> {
121  enum {
122  value = pos < Type,
123  TypesVector<TypesSufix...>> ::value + 1
124  };
125 };
126 
129 template <typename Type, typename... TypesSufix>
130 struct pos<Type, TypesVector<Type, TypesSufix...>> {
131  enum {
132  value = 0
133  };
134 };
135 
137 template <int pos, typename NewType, typename TypesVector>
139 
141 template <int pos, typename NewType, typename TypesPrefix,
142  typename... TypesSufix>
143 struct replace_at_pos<pos, NewType, TypesVector<TypesPrefix, TypesSufix...>> {
144  typedef typename join<
146  typename replace_at_pos<pos - 1, NewType,
147  TypesVector<TypesSufix...>>::type>::type type;
148 };
149 
151 template <typename NewType, typename TypesPrefix, typename... TypesSufix>
152 struct replace_at_pos<0, NewType, TypesVector<TypesPrefix, TypesSufix...>> {
153  typedef TypesVector<NewType, TypesSufix...> type;
154 };
155 
156 } // data_structures
157 } // paal
158 
159 #endif // PAAL_TYPES_VECTOR_HPP
Standard fold function implementation.
Computes size of TypesVector.
replace element at pos to NewType
push back given val to TypesVector
returns pos of the element in the TypesVector
gives element on id in TypesVector
removes first n elements from given TypesVector