Code-Eli  0.3.6
traits.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_util_traits_hpp
14 #define eli_util_traits_hpp
15 
16 #include "eli/code_eli.hpp"
17 
18 //
19 // traits class
20 //
21 namespace eli
22 {
23  namespace util
24  {
25  // always false class
26  template<typename T__>
27  struct always_false
28  {
29  enum {value=false};
30  };
31 
32  // always true class
33  template<typename T__>
34  struct always_true
35  {
36  enum {value=true};
37  };
38 
39  // generic traits class
40  template <typename data__>
41  class traits
42  {
43  public:
44  // how to refer to a constant reference
45  typedef const data__ & const_expr_ref;
46 
47  // how to refer to a reference
48  typedef data__ & expr_ref;
49  };
50 
52  template <typename left__, typename right__>
54  {
56  };
57 
58 #define ELI_UTIL_PROMOTE_TRAITS_INT_HELPER(x_type) \
59  template <> \
60  struct promote_traits<x_type, x_type> \
61  { \
62  typedef x_type promote_t; \
63  }; \
64  template <> \
65  struct promote_traits<x_type, char> \
66  { \
67  typedef x_type promote_t; \
68  }; \
69  template <> \
70  struct promote_traits<char, x_type> \
71  { \
72  typedef x_type promote_t; \
73  }; \
74  template <> \
75  struct promote_traits<x_type, unsigned char> \
76  { \
77  typedef x_type promote_t; \
78  }; \
79  template <> \
80  struct promote_traits<unsigned char, x_type> \
81  { \
82  typedef x_type promote_t; \
83  }; \
84  template <> \
85  struct promote_traits<x_type, short int> \
86  { \
87  typedef x_type promote_t; \
88  }; \
89  template <> \
90  struct promote_traits<short int, x_type> \
91  { \
92  typedef x_type promote_t; \
93  }; \
94  template <> \
95  struct promote_traits<x_type, unsigned short int> \
96  { \
97  typedef x_type promote_t; \
98  }; \
99  template <> \
100  struct promote_traits<unsigned short int, x_type> \
101  { \
102  typedef x_type promote_t; \
103  }; \
104  template <> \
105  struct promote_traits<x_type, int> \
106  { \
107  typedef x_type promote_t; \
108  }; \
109  template <> \
110  struct promote_traits<int, x_type> \
111  { \
112  typedef x_type promote_t; \
113  }; \
114  template <> \
115  struct promote_traits<x_type, unsigned int> \
116  { \
117  typedef x_type promote_t; \
118  }; \
119  template <> \
120  struct promote_traits<unsigned int, x_type> \
121  { \
122  typedef x_type promote_t; \
123  }; \
124  template <> \
125  struct promote_traits<x_type, long int> \
126  { \
127  typedef x_type promote_t; \
128  }; \
129  template <> \
130  struct promote_traits<long int, x_type> \
131  { \
132  typedef x_type promote_t; \
133  }; \
134  template <> \
135  struct promote_traits<x_type, unsigned long int> \
136  { \
137  typedef x_type promote_t; \
138  }; \
139  template <> \
140  struct promote_traits<unsigned long int, x_type> \
141  { \
142  typedef x_type promote_t; \
143  };
144 
145 #define ELI_UTIL_PROMOTE_TRAITS_HELPER(x_type) \
146  ELI_UTIL_PROMOTE_TRAITS_INT_HELPER(x_type) \
147  template <> \
148  struct promote_traits<x_type, float> \
149  { \
150  typedef x_type promote_t; \
151  }; \
152  template <> \
153  struct promote_traits<float, x_type> \
154  { \
155  typedef x_type promote_t; \
156  }; \
157  template <> \
158  struct promote_traits<x_type, double> \
159  { \
160  typedef x_type promote_t; \
161  }; \
162  template <> \
163  struct promote_traits<double, x_type> \
164  { \
165  typedef x_type promote_t; \
166  }; \
167  template <> \
168  struct promote_traits<x_type, long double> \
169  { \
170  typedef x_type promote_t; \
171  }; \
172  template <> \
173  struct promote_traits<long double, x_type> \
174  { \
175  typedef x_type promote_t; \
176  };
177 
178  //
179  // traits promotion definitions for float
180  //
182 
183  //
184  // traits promotion definitions for double
185  //
187  // double-float promotions
188  template <>
189  struct promote_traits<double, float>
190  {
191  typedef double promote_t;
192  };
193  template <>
194  struct promote_traits<float, double>
195  {
196  typedef double promote_t;
197  };
198 
199  //
200  // traits promotion definitions for long double
201  //
203  // long double-float promotions
204  template <>
205  struct promote_traits<long double, float>
206  {
207  typedef long double promote_t;
208  };
209  template <>
210  struct promote_traits<float, long double>
211  {
212  typedef long double promote_t;
213  };
214  // long double-double promotions
215  template <>
216  struct promote_traits<long double, double>
217  {
218  typedef long double promote_t;
219  };
220  template <>
221  struct promote_traits<double, long double>
222  {
223  typedef long double promote_t;
224  };
225  }
226 }
227 #endif
Definition: traits.hpp:41
Definition: math.hpp:20
Definition: traits.hpp:34
long double promote_t
Definition: traits.hpp:218
long double promote_t
Definition: traits.hpp:212
Definition: traits.hpp:27
double promote_t
Definition: traits.hpp:191
data__ & expr_ref
Definition: traits.hpp:48
#define ELI_UTIL_PROMOTE_TRAITS_INT_HELPER(x_type)
Definition: traits.hpp:58
Definition: traits.hpp:51
double promote_t
Definition: traits.hpp:196
long double promote_t
Definition: traits.hpp:207
Definition: traits.hpp:36
long double promote_t
Definition: traits.hpp:223
const data__ & const_expr_ref
Definition: traits.hpp:45
promoted_type_undefined promote_t
Definition: traits.hpp:55
Definition: traits.hpp:53
Definition: traits.hpp:29