plll  1.0
helper.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011-2014 University of Zurich
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #ifndef PLLL_INCLUDE_GUARD__HELPER_HPP
24 #define PLLL_INCLUDE_GUARD__HELPER_HPP
25 
26 #include <plll/config.hpp>
27 
36 namespace plll
37 {
50  namespace helper
51  {
52  namespace implementation
53  {
54  template<bool no_error> struct CompileTimeError;
55  template<> struct CompileTimeError<true> {};
56  }
57 
79 #if __cplusplus >= 201103L
80  #define PLLL_INTERNAL_STATIC_CHECK(condition, IdentifierWhichIsAMessage) \
81  static_assert(condition, #IdentifierWhichIsAMessage);
82 #else
83  #define PLLL_INTERNAL_STATIC_CHECK(condition, IdentifierWhichIsAMessage) \
84  { plll::helper::implementation::CompileTimeError<((condition) != 0)> ERROR_##IdentifierWhichIsAMessage; (void)ERROR_##IdentifierWhichIsAMessage; }
85 #endif
86 
87  namespace implementation
88  {
89  template<bool cond, typename A, typename B>
91  {
92  public:
93  typedef A result;
94  };
95 
96  template<typename A, typename B>
97  class select_first_type_impl<false, A, B>
98  {
99  public:
100  typedef B result;
101  };
102  }
103 
104  template<bool cond, typename A, typename B>
121  {
122  public:
124  typedef typename implementation::select_first_type_impl<cond, A, B>::result result;
125  };
126 
127  namespace implementation
128  {
129  template<typename A, typename B>
131  {
132  enum { result = false };
133  };
134 
135  template<typename A>
136  struct type_equality<A, A>
137  {
138  enum { result = true };
139  };
140  }
141 
142  template<typename A, typename B>
153  {
154  public:
157  };
158 
159  namespace implementation
160  {
161  template<bool cond, typename T>
163  {
164  public:
165  };
166 
167  template<typename T>
168  class enable_if_impl<true, T>
169  {
170  public:
171  };
172  }
173 
174  template<bool cond, typename Type = void>
182  class EnableIf
183  {
184  public:
186  };
187 
188  template<int val>
201  struct IntToType
202  {
203  enum { value = val };
204  };
205 
206  template<bool val>
220  struct BoolToType
221  {
222  enum { value = val };
223  };
224 
225  namespace implementation
226  {
227  template<typename A>
229  {
230  typedef A result;
231  };
232 
233  template<typename A>
234  struct remove_decorations_impl<volatile A>
235  {
237  };
238 
239  template<typename A>
240  struct remove_decorations_impl<const A>
241  {
243  };
244 
245  template<typename A>
247  {
248  typedef typename remove_decorations_impl<A>::result result;
249  };
250 
251 #if __cplusplus >= 201103L
252  template<typename A>
253  struct remove_decorations_impl<A &&>
254  {
255  typedef typename remove_decorations_impl<A>::result result;
256  };
257 #endif
258  }
259 
260  template<typename A>
287  {
290  };
291 
300  template<typename T>
301  T & make_type_lvalue() PLLL_INTERNAL_NOTHROW_POSTFIX_ENFORCE;
302  }
303 }
304 
305 #endif
T & make_type_lvalue() PLLL_INTERNAL_NOTHROW_POSTFIX_ENFORCE
This is a pseudo-template which should only be used in expressions which are never evaluated...
A type comparison template.
Definition: helper.hpp:152
Conversion from compile-time known ints to types.
Definition: helper.hpp:201
Strips decorations const, &, volatile and && from types.
Definition: helper.hpp:286
implementation::remove_decorations_impl< A >::result Result
The stripped type.
Definition: helper.hpp:289
implementation::select_first_type_impl< cond, A, B >::result result
The result type. Either A or B, depending on the value of cond.
Definition: helper.hpp:124
Allows to remove functions from overload resolution.
Definition: helper.hpp:182
Conversion from compile-time known bools to types.
Definition: helper.hpp:220
A type selector template.
Definition: helper.hpp:120