remove \r
[extl.git] / extl / config / suffix.h
blob21e3d50ccd41fba60ecb30d4a5c36cc256bfedc8
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: suffix.h
4 * Created: 08.02.02
5 * Updated: 08.04.14
7 * Brief: The suffix file of configuration
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 /* //////////////////////////////////////////////////////////////////// */
14 #ifndef EXTL_CONFIG_SUFFIX_H
15 #define EXTL_CONFIG_SUFFIX_H
17 #ifndef EXTL_CONFIG_H
18 # error This file must be included of config.h
19 #endif
21 #ifndef EXTL_CONFIG_COMPILER_H
22 # error This file must be depended on compiler\config.h
23 #endif
25 /* ///////////////////////////////////////////////////////////////////////
26 * The detection of template
28 #if defined(__cplusplus) && !defined(EXTL_TEMPLATE_SUPPORT)
29 # error Template support not detected
30 #endif
32 /* ///////////////////////////////////////////////////////////////////////
33 * Specialisation of template
35 #ifdef EXTL_TEMPLATE_SPECIALISATION
36 # undef EXTL_TEMPLATE_SPECIALISATION
37 #endif
39 #ifdef EXTL_TEMPLATE_SPEC_SYNTAX_SUPPORT
40 # define EXTL_TEMPLATE_SPECIALISATION template<>
41 #else
42 # define EXTL_TEMPLATE_SPECIALISATION
43 #endif
45 /* ///////////////////////////////////////////////////////////////////////
46 * The detection of the 64-bit interger
48 #if !defined(EXTL_64BIT_INT_SUPPORT)
49 # error 64-bit is not supported correctlly.
50 #endif
52 /* ///////////////////////////////////////////////////////////////////////
53 * The config of namespace
55 #include "namespace.h"
58 /* ///////////////////////////////////////////////////////////////////////
59 * Reference for compatible C language
61 #ifdef __cplusplus
62 # define _r &
63 # define const_ref const&
64 #else
65 # define _r
66 # define const_ref const
67 #endif
70 /* ///////////////////////////////////////////////////////////////////////
71 * Inline supported
73 #if defined(__cplusplus)
74 # define EXTL_INLINE inline
75 #else
76 # if defined(EXTL_C99_INLINE)
77 # define EXTL_INLINE inline
78 # elif defined(EXTL_CUSTOM_C_INLINE)
79 # define EXTL_INLINE EXTL_CUSTOM_C_INLINE
80 # else
81 # define EXTL_INLINE static
82 # endif
83 #endif
85 /* //////////////////////////////////////////////////////////////////// */
86 /* Calling convention */
87 #ifndef EXTL_CDECL
88 # define EXTL_CDECL
89 #endif
91 #ifndef EXTL_FASTCALL
92 # ifdef EXTL_FASTCALL_SUPPORT
93 # error EXTL_FASTCALL must be defined, when EXTL_FASTCALL_SUPPORT is defined.
94 # else
95 # define EXTL_FASTCALL
96 # endif
97 #endif
99 #ifndef EXTL_STDCALL
100 # ifdef EXTL_STDCALL_SUPPORT
101 # error EXTL_STDCALL must be defined, when EXTL_STDCALL_SUPPORT is defined.
102 # else
103 # define EXTL_STDCALL
104 # endif
105 #endif
107 /* //////////////////////////////////////////////////////////////////// */
108 /* The initialization of static member const */
109 #ifdef __cplusplus
110 # ifdef EXTL_MEMBER_CONST_INIT_SUPPORT
111 # define EXTL_STATIC_MEMBER_CONST(type, assignment) static const type assignment
112 # else
113 # define EXTL_STATIC_MEMBER_CONST(type, assignment) enum { assignment }
114 # endif
115 #else
116 # define EXTL_STATIC_MEMBER_CONST(type, assignment)
117 #endif
119 /* ///////////////////////////////////////////////////////////////////////
120 * Keywords
121 * explicit_k explicit
122 * mutable_k mutable
123 * template_qual_k template eg: typedef A::template a<T>::type type;
124 * typename_param_k typename eg: template < typename T > or template < class T >
125 * typename_type_k typename typename eg: typedef typename template_class<T>::type type;
126 * typename_type_def_k typename eg: template< class A = typename template_class<T>::type >
127 * typename_type_mil_k typename qualifier in constructor initialiser lists
128 * typename_type_ret_k typename eg: typename template_class<T>::type func();
129 * //////////////////////////////////////////////////////////////////// */
131 /* Force all keyword to be supported(used to test) */
132 #ifdef EXTL_FORCE_ALL_KEYWORD_SUPPORT
134 # ifndef EXTL_EXPLICIT_KEYWORD_SUPPORT
135 # define EXTL_EXPLICIT_KEYWORD_SUPPORT
136 # endif
138 # ifndef EXTL_MUTABLE_KEYWORD_SUPPORT
139 # define EXTL_MUTABLE_KEYWORD_SUPPORT
140 # endif
142 # ifndef EXTL_TEMPLATE_QUAL_KEYWORD_SUPPORT
143 # define EXTL_TEMPLATE_QUAL_KEYWORD_SUPPORT
144 # endif
146 # ifndef EXTL_TYPENAME_PARAM_KEYWORD_SUPPORT
147 # define EXTL_TYPENAME_PARAM_KEYWORD_SUPPORT
148 # endif
150 # ifndef EXTL_TYPENAME_TYPE_KEYWORD_SUPPORT
151 # define EXTL_TYPENAME_TYPE_KEYWORD_SUPPORT
152 # endif
154 # ifndef EXTL_TYPENAME_TYPE_DEF_KEYWORD_SUPPORT
155 # define EXTL_TYPENAME_TYPE_DEF_KEYWORD_SUPPORT
156 # endif
158 # ifndef EXTL_TYPENAME_TYPE_MIL_KEYWORD_SUPPORT
159 # define EXTL_TYPENAME_TYPE_MIL_KEYWORD_SUPPORT
160 # endif
162 # ifndef EXTL_TYPENAME_TYPE_RET_KEYWORD_SUPPORT
163 # define EXTL_TYPENAME_TYPE_RET_KEYWORD_SUPPORT
164 # endif
166 #endif
169 /* Keywords */
170 #ifdef EXTL_EXPLICIT_KEYWORD_SUPPORT
171 # define explicit_k explicit
172 #else
173 # define explicit_k
174 #endif
176 #ifdef EXTL_MUTABLE_KEYWORD_SUPPORT
177 # define mutable_k mutable
178 #else
179 # define mutable_k
180 #endif
182 #ifdef EXTL_TEMPLATE_QUAL_KEYWORD_SUPPORT
183 # define template_qual_k template
184 #else
185 # define template_qual_k
186 #endif
188 #ifdef EXTL_TYPENAME_PARAM_KEYWORD_SUPPORT
189 # define typename_param_k typename
190 #else
191 # define typename_param_k class
192 #endif
194 #ifdef EXTL_TYPENAME_TYPE_KEYWORD_SUPPORT
195 # define typename_type_k typename
196 #else
197 # define typename_type_k
198 #endif
200 #ifdef EXTL_TYPENAME_TYPE_DEF_KEYWORD_SUPPORT
201 # define typename_type_def_k typename
202 #else
203 # define typename_type_def_k
204 #endif
206 #ifdef EXTL_TYPENAME_TYPE_MIL_KEYWORD_SUPPORT
207 # define typename_type_mil_k typename
208 #else
209 # define typename_type_mil_k
210 #endif
212 #ifdef EXTL_TYPENAME_TYPE_RET_KEYWORD_SUPPORT
213 # define typename_type_ret_k typename
214 #else
215 # define typename_type_ret_k
216 #endif
218 /* ///////////////////////////////////////////////////////////////////////
219 * Exception signature
221 #if defined(__cplusplus) && \
222 !defined(EXTL_EXCEPTION_SPECIFICATIONS_DISABLE) && \
223 defined(EXTL_EXCEPTION_SIGNATURE_SUPPORT)
225 # define EXTL_THROW throw
226 # define EXTL_THROW_0() throw ()
227 # define EXTL_THROW_1(e1) throw (e1)
228 # define EXTL_THROW_2(e1, e2) throw (e1, e2)
229 # define EXTL_THROW_3(e1, e2, e3) throw (e1, e2, e3)
230 # define EXTL_THROW_4(e1, e2, e3, e4) throw (e1, e2, e3, e4)
231 # define EXTL_THROW_5(e1, e2, e3, e4, e5) throw (e1, e2, e3, e4, e5)
232 # define EXTL_THROW_6(e1, e2, e3, e4, e5, e6) throw (e1, e2, e3, e4, e5, e6)
233 # define EXTL_THROW_7(e1, e2, e3, e4, e5, e6, e7) throw (e1, e2, e3, e4, e5, e6, e7)
234 # define EXTL_THROW_8(e1, e2, e3, e4, e5, e6, e7, e8) throw (e1, e2, e3, e4, e5, e6, e7, e8)
236 #else
237 # define EXTL_THROW
238 # define EXTL_THROW_0()
239 # define EXTL_THROW_1(e1)
240 # define EXTL_THROW_2(e1, e2)
241 # define EXTL_THROW_3(e1, e2, e3)
242 # define EXTL_THROW_4(e1, e2, e3, e4)
243 # define EXTL_THROW_5(e1, e2, e3, e4, e5)
244 # define EXTL_THROW_6(e1, e2, e3, e4, e5, e6)
245 # define EXTL_THROW_7(e1, e2, e3, e4, e5, e6, e7)
246 # define EXTL_THROW_8(e1, e2, e3, e4, e5, e6, e7, e8)
248 #endif
250 /* ///////////////////////////////////////////////////////////////////////
251 * Exception assert
252 * Throws the given exception when the condition is false
254 #if defined(EXTL_EXCEPTION_ENABLE) && \
255 defined(EXTL_EXCEPTION_SUPPORT)
256 # define EXTL_THROW_E(e) throw e
257 # define EXTL_ASSERT_THROW(condition, exception) if(!(condition)) EXTL_THROW_E(exception);
258 #else
259 # define EXTL_THROW_E(e)
260 # define EXTL_ASSERT_THROW(condition, exception)
261 #endif
263 /* ///////////////////////////////////////////////////////////////////////
264 * Exception catch
266 #if defined(EXTL_EXCEPTION_ENABLE) && \
267 defined(EXTL_EXCEPTION_SUPPORT)
269 #define EXTL_TRY try {
270 #define EXTL_CATCH(x) } catch (x) {
271 #define EXTL_CATCH_ALL } catch (...) {
272 #define EXTL_CATCH_END }
274 #else
276 #define EXTL_TRY {{
277 #define EXTL_CATCH(x) } if (0) {
278 #define EXTL_CATCH_ALL } if (0) {
279 #define EXTL_CATCH_END }}
281 #endif
282 /* ///////////////////////////////////////////////////////////////////////
283 * Template param friend
285 template< typename T >
286 class some_class
288 EXTL_DECLARE_TEMPLATE_PARAM_AS_FRIEND(T);
289 private:
290 m_value; // some_class<T>::m_value visible to T
294 #define EXTL_DECLARE_TEMPLATE_PARAM_AS_FRIEND(T) friend T
296 /* ///////////////////////////////////////////////////////////////////////
297 * Boundary alignment
299 #define EXTL_ALIGN(size, boundary) ((size + (boundary - 1)) & ~(boundary - 1))
301 /* ///////////////////////////////////////////////////////////////////////
302 * Line number & File name
304 #define EXTL_LINENUM __LINE__
305 #define EXTL_FILENAME __FILE__
307 /* ///////////////////////////////////////////////////////////////////////
308 * Explicit function template arguments
310 * Some compilers(vc6.0 ...) just generate one instantiation of function templates whose
311 * template parameters don't appear in the function parameter list
312 * e.g.
313 template <int N>
314 func1() { printf("%d\n", N); }
316 template <typename T>
317 func2() { printf("%s\n", typeid(T).name()); }
319 int main()
321 func1<1>();
322 func1<2>();
323 func2<int>();
324 func2<double>();
326 * If it is supported, the output is: 1 2 int double
327 * otherwise, the output is: 2 2 double double
329 * To fix it, write:
330 template <int N>
331 func1(EXTL_EXPLICIT_TEMPLATE_NON_TYPE(int, N)) { printf("%d\n", N); }
333 template <typename T>
334 func2(EXTL_EXPLICIT_TEMPLATE_TYPE(T)) { printf("%s\n", typeid(T).name()); }
336 * the output is: 1 2 int double
338 #if !defined(EXTL_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS_SUPPORT)
339 # define EXTL_EXPLICIT_TEMPLATE_TYPE(t) EXTL_NS(type_wrap)<t>* = 0
340 # define EXTL_APPEND_EXPLICIT_TEMPLATE_TYPE(t) , EXTL_EXPLICIT_TEMPLATE_TYPE(t)
341 #else
342 # define EXTL_EXPLICIT_TEMPLATE_TYPE(t)
343 # define EXTL_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
344 #endif
346 #if !defined(EXTL_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS_SUPPORT) && \
347 defined(EXTL_FUNCTION_TEMPLATE_NON_TYPE_PARAM_SUPPORT)
348 # define EXTL_EXPLICIT_TEMPLATE_NON_TYPE(t, v) EXTL_NS(non_type_wrap)<t, v>* = 0
349 # define EXTL_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) , EXTL_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
350 #else
351 # define EXTL_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
352 # define EXTL_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v)
353 #endif
355 /* //////////////////////////////////////////////////////////////////// */
356 #endif /* EXTL_CONFIG_SUFFIX_H */
357 /* //////////////////////////////////////////////////////////////////// */