summaryrefslogtreecommitdiff
path: root/src/debug/nvwa/c++11.h
blob: 8d8e2d8afe138d3c08b984bab249a1a3f1a50d9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
// vim:tabstop=4:shiftwidth=4:expandtab:

/*
 * Copyright (C) 2013-2017 Wu Yongwei <adah at users dot sourceforge dot net>
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any
 * damages arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute
 * it freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must
 *    not claim that you wrote the original software.  If you use this
 *    software in a product, an acknowledgement in the product
 *    documentation would be appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must
 *    not be misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source
 *    distribution.
 *
 * This file is part of Stones of Nvwa:
 *      http://sourceforge.net/projects/nvwa
 *
 */

/**
 * @file  c++11.h
 *
 * C++11 feature detection macros and workarounds.
 *
 * @date  2017-04-03
 */

#ifndef NVWA_CXX11_H
#define NVWA_CXX11_H

// Only Clang provides these macros; they need to be defined as follows
// to get a valid expression in preprocessing by other compilers.
#ifndef __has_extension
#define __has_extension(x) 0
#endif
#ifndef __has_feature
#define __has_feature(x) 0
#endif
#ifndef __has_include
#define __has_include(x) 0
#endif

// Detect whether C++11 mode is on (for GCC and Clang).  MSVC does not
// have a special C++11 mode, so it is always on for Visual C++ 2010 and
// later.
#if __cplusplus >= 201103L || \
    defined(__GXX_EXPERIMENTAL_CXX0X__) || \
    (defined(_MSC_VER) && _MSC_VER >= 1600)
#define NVWA_CXX11_MODE 1
#else
#define NVWA_CXX11_MODE 0
#endif


/* Feature checks */

#if !defined(HAVE_CXX11_ATOMIC)
#if NVWA_CXX11_MODE && \
    ((__has_include(<atomic>) && !defined(__MINGW32__)) || \
     (defined(_MSC_VER) && _MSC_VER >= 1700) || \
     (((defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 405) || \
       defined(__clang__)) && \
      (!defined(__MINGW32__) || defined(_POSIX_THREADS))))
// Note: MinGW GCC, unless built with POSIX threads (as in
//       MinGW-builds), does not support atomics as of 4.8.
#define HAVE_CXX11_ATOMIC 1
#else
#define HAVE_CXX11_ATOMIC 0
#endif
#endif

#if !defined(HAVE_CXX11_AUTO_TYPE)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_auto_type) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 404))
#define HAVE_CXX11_AUTO_TYPE 1
#else
#define HAVE_CXX11_AUTO_TYPE 0
#endif
#endif

#if !defined(HAVE_CXX11_DELETED_FUNCTION)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_deleted_functions) || \
     (defined(_MSC_VER) && _MSC_VER >= 1800) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 404))
#define HAVE_CXX11_DELETED_FUNCTION 1
#else
#define HAVE_CXX11_DELETED_FUNCTION 0
#endif
#endif

#if !defined(HAVE_CXX11_EXPLICIT_CONVERSION)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_explicit_conversions) || \
     (defined(_MSC_VER) && _MSC_VER >= 1900) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 405))
#define HAVE_CXX11_EXPLICIT_CONVERSION 1
#else
#define HAVE_CXX11_EXPLICIT_CONVERSION 0
#endif
#endif

#if !defined(HAVE_CXX11_FINAL)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_override_control) || \
     (defined(_MSC_VER) && _MSC_VER >= 1700) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 407))
#define HAVE_CXX11_FINAL 1
#else
#define HAVE_CXX11_FINAL 0
#endif
#endif

#if !defined(HAVE_CXX11_FUTURE)
#if NVWA_CXX11_MODE && \
    ((__has_include(<future>) && !defined(__MINGW32__)) || \
     (defined(_MSC_VER) && _MSC_VER >= 1700) || \
     (((defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 405) || \
       defined(__clang__)) && \
      (!defined(__MINGW32__) || defined(_POSIX_THREADS))))
// Note: MinGW GCC, unless built with POSIX threads (as in
//       MinGW-builds), does not support futures as of 4.8.
#define HAVE_CXX11_FUTURE 1
#else
#define HAVE_CXX11_FUTURE 0
#endif
#endif

#if !defined(HAVE_CXX11_GENERALIZED_INITIALIZER)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_generalized_initializers) || \
     (defined(_MSC_VER) && _MSC_VER >= 1800) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 404))
#define HAVE_CXX11_GENERALIZED_INITIALIZER 1
#else
#define HAVE_CXX11_GENERALIZED_INITIALIZER 0
#endif
#endif

#if !defined(HAVE_CXX11_LAMBDA)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_lambdas) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 405))
#define HAVE_CXX11_LAMBDA 1
#else
#define HAVE_CXX11_LAMBDA 0
#endif
#endif

#if !defined(HAVE_CXX11_MUTEX)
#if NVWA_CXX11_MODE && \
    ((__has_include(<mutex>) && !defined(__MINGW32__)) || \
     (defined(_MSC_VER) && _MSC_VER >= 1700) || \
     (((defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \
       defined(__clang__)) && \
      (!defined(__MINGW32__) || defined(_POSIX_THREADS))))
// Note: MinGW GCC, unless built with POSIX threads (as in
//       MinGW-builds), does not support std::mutex as of 4.8.
#define HAVE_CXX11_MUTEX 1
#else
#define HAVE_CXX11_MUTEX 0
#endif
#endif

#if !defined(HAVE_CXX11_NOEXCEPT)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_noexcept) || \
     (defined(_MSC_VER) && _MSC_VER >= 1900) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
#define HAVE_CXX11_NOEXCEPT 1
#else
#define HAVE_CXX11_NOEXCEPT 0
#endif
#endif

#if !defined(HAVE_CXX11_NULLPTR)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_nullptr) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
#define HAVE_CXX11_NULLPTR 1
#else
#define HAVE_CXX11_NULLPTR 0
#endif
#endif

#if !defined(HAVE_CXX11_OVERRIDE)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_override_control) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 407))
#define HAVE_CXX11_OVERRIDE 1
#else
#define HAVE_CXX11_OVERRIDE 0
#endif
#endif

#if !defined(HAVE_CXX11_RANGE_FOR)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_range_for) || \
     (defined(_MSC_VER) && _MSC_VER >= 1700) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
#define HAVE_CXX11_RANGE_FOR 1
#else
#define HAVE_CXX11_RANGE_FOR 0
#endif
#endif

#if !defined(HAVE_CXX11_RVALUE_REFERENCE)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_rvalue_references) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 405))
#define HAVE_CXX11_RVALUE_REFERENCE 1
#else
#define HAVE_CXX11_RVALUE_REFERENCE 0
#endif
#endif

#if !defined(HAVE_CXX11_STATIC_ASSERT)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_static_assert) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 403))
#define HAVE_CXX11_STATIC_ASSERT 1
#else
#define HAVE_CXX11_STATIC_ASSERT 0
#endif
#endif

#if !defined(HAVE_CXX11_THREAD)
#if NVWA_CXX11_MODE && \
    ((__has_include(<thread>) && !defined(__MINGW32__)) || \
     (defined(_MSC_VER) && _MSC_VER >= 1700) || \
     (((defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 404) || \
       defined(__clang__)) && \
      (!defined(__MINGW32__) || defined(_POSIX_THREADS))))
// Note: MinGW GCC, unless built with POSIX threads (as in
//       MinGW-builds), does not support std::thread as of 4.8.
#define HAVE_CXX11_THREAD 1
#else
#define HAVE_CXX11_THREAD 0
#endif
#endif

#if !defined(HAVE_CXX11_THREAD_LOCAL)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_thread_local) || \
     (defined(_MSC_VER) && _MSC_VER >= 1900) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 408))
#define HAVE_CXX11_THREAD_LOCAL 1
#else
#define HAVE_CXX11_THREAD_LOCAL 0
#endif
#endif

#if !defined(HAVE_CXX11_TYPE_TRAITS)
#if NVWA_CXX11_MODE && \
    (__has_include(<type_traits>) || \
     (defined(_MSC_VER) && _MSC_VER >= 1600) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 403))
#define HAVE_CXX11_TYPE_TRAITS 1
#else
#define HAVE_CXX11_TYPE_TRAITS 0
#endif
#endif

#if !defined(HAVE_CXX11_UNICODE_LITERAL)
#if NVWA_CXX11_MODE && \
    (__has_feature(cxx_unicode_literals) || \
     (defined(_MSC_VER) && _MSC_VER >= 1900) || \
     (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 405))
#define HAVE_CXX11_UNICODE_LITERAL 1
#else
#define HAVE_CXX11_UNICODE_LITERAL 0
#endif
#endif


/* Workarounds */

#if HAVE_CXX11_DELETED_FUNCTION
#define _DELETED = delete
#else
#define _DELETED
#endif

#if HAVE_CXX11_FINAL
#define _FINAL final
#else
#define _FINAL
#endif

#if HAVE_CXX11_OVERRIDE
#define _OVERRIDE override
#else
#define _OVERRIDE
#endif

#if HAVE_CXX11_NOEXCEPT
#define _NOEXCEPT noexcept
#define _NOEXCEPT_(x) noexcept(x)
#else
#ifdef _MSC_VER
#define _NOEXCEPT throw ()
#else
#define _NOEXCEPT throw()
#endif
#define _NOEXCEPT_(x)
#endif

#if HAVE_CXX11_NULLPTR
#define _NULLPTR nullptr
#else
#define _NULLPTR NULL
#endif

#if HAVE_CXX11_THREAD_LOCAL
#define _THREAD_LOCAL thread_local
#else
#ifdef _MSC_VER
#define _THREAD_LOCAL __declspec(thread)
#else
#define _THREAD_LOCAL __thread
#endif
#endif

#endif // NVWA_CXX11_H