/
cpp11.h
366 lines (323 loc) · 9.2 KB
/
cpp11.h
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#pragma once
// The reason this header exists is due to the asymmetric availability of C++11 on our
// various compiler targets. In particular, none of the typical headers for C++11 support
// exist when building with libstdc++ on Apple, so we have to disable it across the board.
#ifdef __APPLE__
#include <ciso646> // detect std::lib
#ifdef _LIBCPP_VERSION // clang + libc++
#define STL11_ALLOWED 1
#else // clang + libstdc++
#define STL11_ALLOWED 0
#endif
#else // gcc or MSVC
#define STL11_ALLOWED 1
#endif
// Deprecated macros, provided here until we can be sure that they aren't used downstream
#define throw_rethrowable throw
#define EXCEPTION_PTR_HEADER <stdexcept>
#define IS_CLANG defined(__clang_major__)
#define CLANG_CHECK(maj, min) (__clang_major__ == maj && __clang_minor__ >= min || __clang_major__ > maj)
#define GCC_CHECK(maj, min) (__GNUC__ == maj && __GNUC_MINOR__ >= min || __GNUC__ > maj)
// If Boost.Thread is used, we want it to provide the new name for its <future> class
#define BOOST_THREAD_PROVIDES_FUTURE
#ifndef __has_feature
#define __has_feature(x) (AUTOWIRE_##x)
#endif
/*********************
* __func__ function name support
*********************/
#ifdef _MSC_VER
#define __func__ __FUNCTION__
#endif
/*********************
* Location of the unordered_set header
*********************/
#if defined(__APPLE__) && !defined(_LIBCPP_VERSION)
#define STL_UNORDERED_SET <autowiring/C++11/tr1_unordered_set.h>
#define STL_UNORDERED_MAP <autowiring/C++11/tr1_unordered_map.h>
#else
#define STL_UNORDERED_SET <unordered_set>
#define STL_UNORDERED_MAP <unordered_map>
#endif
/*********************
* initializer_list header
*********************/
#if IS_CLANG
#define HAS_INITIALIZER_LIST __has_feature(cxx_generalized_initializers)
#if HAS_INITIALIZER_LIST
#define INITIALIZER_LIST_HEADER <initializer_list>
#else
#define INITIALIZER_LIST_HEADER <autowiring/C++11/empty_file.h>
#endif
#else
#define HAS_INITIALIZER_LIST 1
#define INITIALIZER_LIST_HEADER <initializer_list>
#endif
/*********************
* Check override keyword availability
*********************/
#if __cplusplus < 201103 && !defined(_MSC_VER)
#define override
#endif
/*********************
* static_assert availability
*********************/
#if CLANG_CHECK(2, 9) || GCC_CHECK(4, 3)
#define HAS_STATIC_ASSERT 1
#elif _MSC_VER >= 1500
#define HAS_STATIC_ASSERT 1
#else
#define HAS_STATIC_ASSERT 0
#endif
#if !HAS_STATIC_ASSERT || !STL11_ALLOWED
// Static assert completely disabled if it's not available
#define static_assert(...)
#endif
#if defined(_MSC_VER) || !IS_CLANG
#define AUTOWIRE_cxx_override_control 1
#endif
/*********************
* system error availability
*********************/
#if STL11_ALLOWED
#define SYSTEM_ERROR_HEADER <system_error>
#else
#define SYSTEM_ERROR_HEADER <autowiring/C++11/boost_system_error.h>
#endif
/*********************
* future availability
*********************/
#if (_MSC_VER >= 1700 || (STL11_ALLOWED)) && !__ANDROID__
#define FUTURE_HEADER <future>
#else
// As of NDK r10, we still don't have an implementation of "future" for Android
#define FUTURE_HEADER <autowiring/C++11/boost_future.h>
#endif
/**
* type_index support
*/
// Supported natively on any platform except Mac/libstdc++
#if STL11_ALLOWED
#define TYPE_INDEX_HEADER <typeindex>
#else
#define TYPE_INDEX_HEADER <autowiring/C++11/type_index.h>
#endif
/*********************
* Decide what version of type_traits we are going to use
*********************/
#if _MSC_VER >= 1500
#define TYPE_TRAITS_AVAILABLE 1
#elif __GXX_EXPERIMENTAL_CXX0X__ && STL11_ALLOWED
#define TYPE_TRAITS_AVAILABLE 1
#else
#define TYPE_TRAITS_AVAILABLE 0
#endif
#if TYPE_TRAITS_AVAILABLE
#define TYPE_TRAITS_HEADER <type_traits>
#else
#define TYPE_TRAITS_HEADER <autowiring/C++11/boost_type_traits.h>
#endif
/*********************
* Decide what version of shared_ptr we are going to use
*********************/
// Shared pointer available in VS10
#if _MSC_VER >= 1500
#define SHARED_PTR_IN_STL 1
#elif __cplusplus > 199711L || __GXX_EXPERIMENTAL_CXX0X__
#define SHARED_PTR_IN_STL 1
#else
#define SHARED_PTR_IN_STL 0
#endif
#if SHARED_PTR_IN_STL && STL11_ALLOWED
#define MEMORY_HEADER <autowiring/C++11/memory.h>
#else
#define MEMORY_HEADER <autowiring/C++11/memory_nostl11.h>
#endif
// Nullptr_t has odd availability
#ifdef _MSC_VER
#define HAS_NULLPTR_T 1
#elif IS_CLANG
#define HAS_NULLPTR_T (STL11_ALLOWED && __has_feature(cxx_nullptr))
#elif __cplusplus > 199711L
#define HAS_NULLPTR_T 1
#else
// No idea--better safe than sorry!
#define HAS_NULLPTR_T 1
#endif
#if ! HAS_NULLPTR_T
// Have to provide our own dummy type, then, there's no header for this one
namespace std { typedef decltype(nullptr) nullptr_t; }
#endif
/*********************
* Specific support for is_constructible
*********************/
#ifdef _MSC_VER
#define AUTOWIRE_cxx_is_constructible 1
#elif IS_CLANG
#define AUTOWIRE_cxx_is_constructible STL11_ALLOWED
#else
#define AUTOWIRE_cxx_is_constructible 1
#endif
/*********************
* noexcept support
*********************/
#ifdef _MSC_VER
#define AUTOWIRE_cxx_noexcept 0
#define NOEXCEPT(x)
#else
#define AUTOWIRE_cxx_noexcept 1
#define NOEXCEPT(x) x noexcept
#endif
/*********************
* Lambdas?
*********************/
#if _MSC_VER >= 1500
#define LAMBDAS_AVAILABLE 1
#elif CLANG_CHECK(3, 2)
// Only available if we're told we're using at least C++11
#if __cplusplus >= 201103L
#define LAMBDAS_AVAILABLE 1
#else
#define LAMBDAS_AVAILABLE 0
#endif
#elif __GXX_EXPERIMENTAL_CXX0X__
#define LAMBDAS_AVAILABLE 1
#endif
#if LAMBDAS_AVAILABLE && STL11_ALLOWED
#define FUNCTIONAL_HEADER <functional>
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#else
#define FUNCTIONAL_HEADER <autowiring/C++11/boost_functional.h>
#endif
#ifndef LAMBDAS_AVAILABLE
#define LAMBDAS_AVAILABLE 0
#endif
/*********************
* Arrays?
*********************/
#if _MSC_VER >= 1500
#define ARRAYS_AVAILABLE 1
#elif __GXX_EXPERIMENTAL_CXX0X__ && STL11_ALLOWED
#define ARRAYS_AVAILABLE 1
#else
#define ARRAYS_AVAILABLE 0
#endif
#if ARRAYS_AVAILABLE
#define ARRAY_HEADER <array>
#else
#define ARRAY_HEADER <autowiring/C++11/boost_array.h>
#endif
/**
* Standard language features
**/
#define _WEBSOCKETPP_RVALUE_REFERENCES_
#define _WEBSOCKETPP_DELETED_FUNCTIONS_
/**
* R-value reference check
*/
#if STL11_ALLOWED
#define RVALUE_HEADER <memory>
#define _WEBSOCKETPP_CPP11_MEMORY_
#else
// Remove literal references in order to fix another missing header problem on *nix
// Defined by default on C++11 Clang
#if !defined(__APPLE__) || __cplusplus >= 201103L
#define BOOST_NO_UNICODE_LITERALS 1
#endif
#define RVALUE_HEADER <autowiring/C++11/boost_rvalue.h>
#endif
/**
* Atomic
*/
#if STL11_ALLOWED
#define ATOMIC_HEADER <atomic>
#else
#define ATOMIC_HEADER <autowiring/C++11/boost_atomic.h>
#endif
/**
* Tuple
*/
#if STL11_ALLOWED
#define STL_TUPLE_HEADER <tuple>
#else
#define STL_TUPLE_HEADER <autowiring/C++11/boost_tuple.h>
#endif
/**
* Mutex
*/
#if STL11_ALLOWED
#define MUTEX_HEADER <autowiring/C++11/mutex.h>
#else
#define MUTEX_HEADER <autowiring/C++11/boost_mutex.h>
#endif
/**
* Thread
*/
#if STL11_ALLOWED
#define THREAD_HEADER <thread>
#define _WEBSOCKETPP_CPP11_THREAD_
#else
#define THREAD_HEADER <autowiring/C++11/boost_thread.h>
#endif
/**
* Chrono
*/
#define CHRONO_HEADER <autowiring/C++11/chrono_with_profiling_clock.h>
/**
* Utility
*/
#if STL11_ALLOWED
#define UTILITY_HEADER <utility>
#else
#define UTILITY_HEADER <autowiring/C++11/boost_utility.h>
#endif
/**
* System error
*/
#if STL11_ALLOWED
#define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
#endif
/*********************
* Deprecation convenience macro
*********************/
#ifndef _DEBUG
#ifdef _MSC_VER
#define DEPRECATED(signature, msg) __declspec(deprecated(msg)) signature
#define DEPRECATED_CLASS(classname, msg) __declspec(deprecated(msg)) classname
#define DEPRECATED_MEMBER(member, msg) member
#else
#define DEPRECATED(signature, msg) signature __attribute__((deprecated))
#define DEPRECATED_CLASS(classname, msg) classname
#define DEPRECATED_MEMBER(member, msg) DEPRECATED(member, msg)
#endif
#else
#define DEPRECATED(signature, msg) signature
#define DEPRECATED_CLASS(classname, msg) classname
#define DEPRECATED_MEMBER(member, msg) member
#endif
/*********************
* Enum forward declaration convenience macro - VS2010 has a bad implementation
*********************/
#if defined(_MSC_VER) && _MSC_VER <= 1600
#define DECLARE_ENUM(x,type) enum x
#else
#define DECLARE_ENUM(x,type) enum x : type
#endif
/*****
* Aligned memory allocation
*****/
#ifdef _MSC_VER
#define ALIGNED_ALLOC_HEADER <malloc.h>
#define cpp11_aligned_alloc(alignment, size) _aligned_malloc(size, alignment)
#define cpp11_aligned_free _aligned_free
#elif defined(__APPLE__) && defined(__MACH__)
// On Mac, memory is already 16-byte aligned
#define ALIGNED_ALLOC_HEADER <stdlib.h>
#define cpp11_aligned_alloc(alignment, size) malloc(size)
#define cpp11_aligned_free free
#else
#define ALIGNED_ALLOC_HEADER <malloc.h>
#define cpp11_aligned_alloc memalign
#define cpp11_aligned_free free
#endif