GL Studio C++ Runtime API
gls_cpp_lang_support.h
Go to the documentation of this file.
1/// \file gls_cpp_lang_support.h
2/// \brief Macros and helper code to determine what subset of C++11/14/17 is available.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2016 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef INCLUDED_GLS_CPP_LANG_SUPPORT_H
40#define INCLUDED_GLS_CPP_LANG_SUPPORT_H
41
42// Conditional C++11/14 support
43//
44// We use a subset of C++11/14 features to improve efficiency and correctness of code.
45//
46// We attempt to detect compiler support, but for unusual configurations, it can be
47// enabled with project-level defines. Define DISTI_HAS_CPP11 to enable all features.
48// Enable specific features by defining any of the following:
49//
50// DISTI_HAS_RVAL_REFS // For rvalue references
51// DISTI_HAS_METHOD_OVERRIDE // For "override" and "final" keywords
52// DISTI_HAS_NOEXCEPT // For "noexcept" keyword
53// DISTI_HAS_SPECIAL_MEM_FUN_DEL // For "= delete"
54// DISTI_HAS_TYPE_TRAITS // For compile-time checking via type-traits
55// DISTI_HAS_STATIC_ASSERT // For static_assert support
56// DISTI_HAS_DEPRECATED_ATTRIBUTE // For [[deprecated("why")]] attribute
57// DISTI_HAS_USER_DEFINED_LITERALS // For operator""_myLiteral
58//
59// If our detection is incorrect, override it with a corresponding "NO" define:
60//
61// DISTI_NO_RVAL_REFS // For rvalue references
62// DISTI_NO_METHOD_OVERRIDE // For "override" and "final" keywords
63// DISTI_NO_NOEXCEPT // For "noexcept" keyword
64// DISTI_NO_SPECIAL_MEM_FUN_DEL // For "= delete"
65// DISTI_NO_TYPE_TRAITS // For compile-time checking via type-traits
66// DISTI_NO_STATIC_ASSERT // For static_assert support
67// DISTI_NO_DEPRECATED_ATTRIBUTE // For [[deprecated("why")]] attribute
68// DISTI_NO_USER_DEFINED_LITERALS // For operator""_myLiteral
69/////////////////////////////////////////////////////////////////////////////////////
70// Microsoft C++ Compiler -- https://msdn.microsoft.com/en-us/library/hh567368.aspx
71/////////////////////////////////////////////////////////////////////////////////////
72#if defined( _MSC_VER )
73# if _MSC_VER >= 1700 // >= VS2012
74# define DISTI_HAS_RVAL_REFS
75# define DISTI_HAS_METHOD_OVERRIDE
76# define DISTI_HAS_TYPE_TRAITS
77# define DISTI_HAS_STATIC_ASSERT
78# endif
79# if _MSC_VER >= 1800 // >= VS2013
80# define DISTI_HAS_SPECIAL_MEM_FUN_DEL
81# define DISTI_HAS_CPP11
82# endif
83# if _MSC_VER >= 1900 // >= VS2015
84# define DISTI_HAS_USER_DEFINED_LITERALS
85# endif
86# if _MSC_VER >= 1911 && __cplusplus >= 201402L // >= VS2017 15.3
87# define DISTI_HAS_NOEXCEPT
88# define DISTI_HAS_DEPRECATED_ATTRIBUTE
89# define DISTI_HAS_CPP14
90# endif
91
92////////////////////////////////////////////////////////////////////////////////
93// GCC versions -- https://gcc.gnu.org/projects/cxx-status.html#cxx11
94////////////////////////////////////////////////////////////////////////////////
95#elif defined( __GNUC__ ) && !defined( __clang__ )
96// __cpp_rvalue_references doesn't seem to be defined in GCC, despite the documentation, so we have an alternative check also
97# if __cpp_rvalue_references >= 200610 || ( ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 3 ) ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || __cplusplus >= 201103L ) )
98# define DISTI_HAS_RVAL_REFS
99# endif
100# if __cpp_static_assert >= 200410 && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || __cplusplus >= 201103L )
101# define DISTI_HAS_STATIC_ASSERT
102# endif
103# if( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 9 ) ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || __cplusplus >= 201103L )
104# define DISTI_HAS_USER_DEFINED_LITERALS
105# endif
106# if( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 7 ) ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || __cplusplus >= 201103L )
107# define DISTI_HAS_METHOD_OVERRIDE
108# define DISTI_HAS_NOEXCEPT
109# define DISTI_HAS_TYPE_TRAITS // This actually depends on which standard library is in use, but it's a safe bet.
110# define DISTI_HAS_CPP11
111# endif
112# if( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) ) && ( defined( __GXX_EXPERIMENTAL_CXX0X__ ) || __cplusplus >= 201103L )
113# define DISTI_HAS_SPECIAL_MEM_FUN_DEL
114# endif
115# if( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 9 ) ) && __cplusplus >= 201402L
116# define DISTI_HAS_DEPRECATED_ATTRIBUTE
117# define DISTI_HAS_CPP14
118# endif
119
120////////////////////////////////////////////////////////////////////////////////
121// Clang versions -- http://clang.llvm.org/cxx_status.html
122////////////////////////////////////////////////////////////////////////////////
123#elif defined( __clang__ )
124# if __has_feature( cxx_rvalue_references )
125# define DISTI_HAS_RVAL_REFS
126# define DISTI_HAS_CPP11 // Guess that if we have rvalue refs, we've got pretty solid C++11 support
127# endif
128# if __has_feature( cxx_override_control )
129# define DISTI_HAS_METHOD_OVERRIDE
130# endif
131# if __has_feature( cxx_noexcept )
132# define DISTI_HAS_NOEXCEPT
133# endif
134# if __has_feature( cxx_defaulted_functions ) && __has_feature( cxx_deleted_functions )
135# define DISTI_HAS_SPECIAL_MEM_FUN_DEL
136# endif
137# if __has_feature( cxx_static_assert )
138# define DISTI_HAS_STATIC_ASSERT
139# endif
140# if __has_feature( cxx_user_literals )
141# define DISTI_HAS_USER_DEFINED_LITERALS
142# endif
143# if( __clang_major__ > 3 || ( __clang_major__ == 3 && __clang_minor__ >= 4 ) ) && __cplusplus >= 201402L
144# define DISTI_HAS_DEPRECATED_ATTRIBUTE
145# define DISTI_HAS_CPP14
146# endif
147// This actually depends on which standard library is in use, but it's a safe bet.
148# define DISTI_HAS_TYPE_TRAITS
149#endif
150
151///////////////////////////////////////////////////////////////////////////////////////////////////
152// Shortcut for unrecognized compilers
153///////////////////////////////////////////////////////////////////////////////////////////////////
154// A single switch to enable everything since compiler is highly compliant
155// These macros can help with cross-platform portability
156#ifdef DISTI_HAS_CPP14
157/// Defines whether or not C++11 support is available.
158# define DISTI_HAS_CPP11
159/// Defines whether this compiler supports the C++14 deprecated attribute.
160# define DISTI_HAS_DEPRECATED_ATTRIBUTE
161#endif
162
163#ifdef DISTI_HAS_CPP11
164/// Macro to wrap code that should be excluded if C++11 support is not available.
165# define DISTI_IF_HAS_CPP11( x ) x
166/// Macro to wrap code that has two implementations, one for C++11 support and the other without.
167# define DISTI_IF_HAS_CPP11_ELSE( x, y ) x
168
169/// Defines whether or not this compiler supports move semantics.
170# define DISTI_HAS_RVAL_REFS
171/// Defines whether or not this compiler supports the override keyword.
172# define DISTI_HAS_METHOD_OVERRIDE
173/// Defines whether or not this compiler supports deleted functions.
174# define DISTI_HAS_SPECIAL_MEM_FUN_DEL
175/// Defines whether or not this compiler supports type traits.
176# define DISTI_HAS_TYPE_TRAITS
177/// Defines whether or not this compiler supports static assertion.
178# define DISTI_HAS_STATIC_ASSERT
179#else
180// Not fully C++11; some features may be enabled piecemeal
181// These macros can help with cross-platform portability
182
183/// Macro to wrap code that should be excluded if C++11 support is not available.
184# define DISTI_IF_HAS_CPP11( x )
185/// Macro to wrap code that has two implementations, one for C++11 support and the other without.
186# define DISTI_IF_HAS_CPP11_ELSE( x, y ) y
187#endif
188
189///////////////////////////////////////////////////////////////////////////////////////////////////
190// Individual C++11 features. See comment above on DISTI_NO_* vs. DISTI_HAS_* macros.
191///////////////////////////////////////////////////////////////////////////////////////////////////
192#if !defined( DISTI_NO_RVAL_REFS ) && defined( DISTI_HAS_RVAL_REFS )
193# include <utility>
194/// Macro to wrap std::move, removed on compilers that don't support it.
195# define DISTI_RVAL_MOVE( x ) std::move( x )
196/// Macro to wrap std::forward, removed on compilers that don't support it.
197# define DISTI_UREF_FORWARD( T, x ) std::forward<T>( x )
198/// Macro to wrap r-value reference, removed on platforms that don't support it.
199# define DISTI_UREF( T ) T&&
200/// Macro to wrap code that should be excluded if r-value references aren't supported.
201# define DISTI_IF_HAS_RVAL_REFS( x ) x
202/// Macro to wrap code that has two implementations, one for r-value reference support, and the other without.
203# define DISTI_IF_HAS_RVAL_REFS_ELSE( x, y ) x
204#else
205# undef DISTI_HAS_RVAL_REFS
206/// Macro to wrap std::move, removed on compilers that don't support it.
207# define DISTI_RVAL_MOVE( x ) x
208/// Macro to wrap std::forward, removed on compilers that don't support it.
209# define DISTI_UREF_FORWARD( T, x ) x
210/// Macro to wrap r-value reference, removed on platforms that don't support it.
211# define DISTI_UREF( T ) const T&
212/// Macro to wrap code that should be excluded if r-value references aren't supported.
213# define DISTI_IF_HAS_RVAL_REFS( x )
214/// Macro to wrap code that has two implementations, one for r-value reference support, and the other without.
215# define DISTI_IF_HAS_RVAL_REFS_ELSE( x, y ) y
216#endif
217
218///////////////////////////////////////////////////////////////////////////////////////////////////
219#if !defined( DISTI_NO_METHOD_OVERRIDE ) && defined( DISTI_HAS_METHOD_OVERRIDE )
220/// Macro to wrap the override keyword, removed on compilers that don't support it.
221# define DISTI_METHOD_OVERRIDE override
222/// Macro to wrap the final keyword, removed on compilers that don't support it.
223# define DISTI_FINAL final
224#else
225# undef DISTI_HAS_METHOD_OVERRIDE
226/// Macro to wrap the override keyword, removed on compilers that don't support it.
227# define DISTI_METHOD_OVERRIDE
228/// Macro to wrap the final keyword, removed on compilers that don't support it.
229# define DISTI_FINAL
230#endif
231
232///////////////////////////////////////////////////////////////////////////////////////////////////
233#if !defined( DISTI_NO_NOEXCEPT ) && defined( DISTI_HAS_NOEXCEPT )
234/// Macro to wrap the noexcept keyword, removed on compilers that don't support it.
235# define DISTI_FUNC_NOEXCEPT noexcept
236#else
237# undef DISTI_HAS_NOEXCEPT
238/// Macro to wrap the noexcept keyword, removed on compilers that don't support it.
239# define DISTI_FUNC_NOEXCEPT
240#endif
241
242///////////////////////////////////////////////////////////////////////////////////////////////////
243#if !defined( DISTI_NO_SPECIAL_MEM_FUN_DEL ) && defined( DISTI_HAS_SPECIAL_MEM_FUN_DEL )
244/// Macro to wrap function deletion, removed on compilers that don't support it.
245# define DISTI_SPECIAL_MEM_FUN_DELETE = delete
246#else
247# undef DISTI_HAS_SPECIAL_MEM_FUN_DEL
248/// Macro to wrap function deletion, removed on compilers that don't support it.
249# define DISTI_SPECIAL_MEM_FUN_DELETE
250#endif
251
252///////////////////////////////////////////////////////////////////////////////////////////////////
253#if !defined( DISTI_NO_USER_DEFINED_LITERALS ) && defined( DISTI_HAS_USER_DEFINED_LITERALS )
254/// Macro to wrap user defined literals, removed on compilers that don't support them.
255# define DISTI_IF_HAS_USER_DEFINED_LITERAL( x ) x
256#else
257# undef DISTI_HAS_USER_DEFINED_LITERALS
258/// Macro to wrap user defined literals, removed on compilers that don't support them.
259# define DISTI_IF_HAS_USER_DEFINED_LITERAL( x )
260#endif
261
262///////////////////////////////////////////////////////////////////////////////////////////////////
263#if !defined( DISTI_NO_TYPE_TRAITS ) && defined( DISTI_HAS_TYPE_TRAITS )
264/// Use this by including <type_traits> and then providing a default, e.g.,
265/// \code{.cpp}
266/// DISTI_IF_HAS_TYPE_TRAITS_ELSE( std::is_const<T>::value, false )
267/// \endcode
268# define DISTI_IF_HAS_TYPE_TRAITS_ELSE( x, y ) x
269
270////////////////////////////////////////////////////////////////////////////////
271/// Convenience macro to check that one type converts to another at compile-time.
272/// \param T A class to check
273/// \param ConvertsTo A class to test T* against to verify that it can be
274/// converted to ConvertsTo* without a cast.
275////////////////////////////////////////////////////////////////////////////////
276# define DISTI_STATIC_ASSERT_IS_CONVERTIBLE_TO( T, ConvertsTo ) DISTI_STATIC_ASSERT( ( std::is_convertible<T*, ConvertsTo*>::value ), class_does_not_inherit_from_##ConvertsTo );
277
278/// Determines if a class \a T is trivially destructible (i.e., has no side effects)
279# define DISTI_IS_TRIVIALLY_DESTRUCTIBLE( T ) ( std::is_trivially_destructible<T>() )
280/// Macro wrapping std::true_type, removed on compilers that don't support it.
281# define DISTI_TT_TRUE_TYPE std::true_type
282/// Macro wrapping std::false_type, removed on compilers that don't support it.
283# define DISTI_TT_FALSE_TYPE std::false_type
284#else
285# undef DISTI_HAS_TYPE_TRAITS
286/// Use this by including <type_traits> and then providing a default, e.g.,
287/// \code{.cpp}
288/// DISTI_IF_HAS_TYPE_TRAITS_ELSE( std::is_const<T>::value, false )
289/// \endcode
290# define DISTI_IF_HAS_TYPE_TRAITS_ELSE( x, y ) y
291
292# ifndef DOXYGEN_IGNORE
293/// See documentation above
294# define DISTI_STATIC_ASSERT_IS_CONVERTIBLE_TO( T, ConvertsTo ) DISTI_STATIC_ASSERT( ( ::disti::_cppLangSupportDetail::is_convertible<T*, ConvertsTo*>::value ), class_does_not_inherit_from_##ConvertsTo )
295
296/// See documentation above
297# define DISTI_IS_TRIVIALLY_DESTRUCTIBLE( T ) ( ::disti::_cppLangSupportDetail::is_trivially_destructible<T>() )
298# define DISTI_TT_TRUE_TYPE ::disti::_cppLangSupportDetail::true_type
299# define DISTI_TT_FALSE_TYPE ::disti::_cppLangSupportDetail::false_type
300# endif
301
302namespace disti
303{
304// The _cppLangSupportDetail namespace is here to hide implementation details, mostly for things
305// that are standard but not available on all supported platforms.
306namespace _cppLangSupportDetail
307{
308 /// Replacement for std::is_convertible, adapted from Loki 0.1.7.
309 /////////////////////////////////////////////////////////////////////////////////
310 /// \copyright The Loki Library, Copyright (c) 2001 by Andrei Alexandrescu<br />
311 /// This code accompanies the book:
312 /// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
313 /// Patterns Applied". Copyright (c) 2001. Addison-Wesley.<br />
314 /// Permission to use, copy, modify, distribute and sell this software for any
315 /// purpose is hereby granted without fee, provided that the above copyright
316 /// notice appear in all copies and that both that copyright notice and this
317 /// permission notice appear in supporting documentation.<br />
318 /// The author or Addison-Welsey Longman make no representations about the
319 /// suitability of this software for any purpose. It is provided "as is"
320 /// without express or implied warranty.<br />
321 /////////////////////////////////////////////////////////////////////////////////
322 template<class T, class U>
323 struct is_convertible
324 {
325 private:
326 typedef char Small;
327 struct Big
328 {
329 char dummy[ 2 ];
330 };
331 static Big Test( ... );
332 static Small Test( U );
333 static T MakeT();
334
335 public:
336 enum
337 {
338 value = sizeof( Small ) == sizeof( ( Test( MakeT() ) ) )
339 };
340 };
341
342 // clang-format off
343 /// Replacement for std::is_convertible, adapted from Loki 0.1.7.
344 template<class T> struct is_convertible<T, T > { enum { value = true }; };
345
346 /// Replacement for std::is_convertible, adapted from Loki 0.1.7.
347 template<class T> struct is_convertible<void, T > { enum { value = false }; };
348
349 /// Replacement for std::is_convertible, adapted from Loki 0.1.7.
350 template<class T> struct is_convertible<T, void> { enum { value = false }; };
351
352 /// Replacement for std::is_convertible, adapted from Loki 0.1.7.
353 template<> struct is_convertible<void, void> { enum { value = true }; };
354
355# if defined( DISTI_USER_DEFINED_IS_TRIVIALLY_DESTRUCTIBLE ) // Prefer the user-defined version if available
356# define DISTI_TT_IS_TRIVIALLY_DESTRUCTIBLE( T ) ( DISTI_USER_DEFINED_IS_TRIVIALLY_DESTRUCTIBLE( T ) )
357# else
358 // Use compiler intrinsics for something that cannot be reliably determined without it.
359 // Drawn from Boost 1.55.0's implementation.
360# if defined( _MSC_VER )
361# define DISTI_TT_IS_TRIVIALLY_DESTRUCTIBLE( T ) ( __has_trivial_destructor( T ) || ( __is_pod( T ) && __has_trivial_constructor( T ) ) )
362# else
363 // This is defined for all supported versions of GCC and Clang and is also common elsewhere.
364 // Define DISTI_USER_DEFINED_IS_TRIVIALLY_DESTRUCTIBLE() to override.
365# define DISTI_TT_IS_TRIVIALLY_DESTRUCTIBLE( T ) ( __has_trivial_destructor( T ) )
366# endif
367# endif
368# if defined( DISTI_USER_DEFINED_IS_DESTRUCTIBLE ) // Prefer the user-defined version if available
369# define DISTI_TT_IS_DESTRUCTIBLE( T ) ( DISTI_USER_DEFINED_IS_DESTRUCTIBLE( T ) )
370# else
371 // This is defined for all supported versions of GCC and Clang and is also common elsewhere.
372 // Define DISTI_USER_DEFINED_IS_DESTRUCTIBLE() to override.
373# define DISTI_TT_IS_DESTRUCTIBLE( T ) ( __is_pod( T ) || __is_class( T ) )
374# endif
375 // clang-format on
376
377# ifndef DOXYGEN_IGNORE
378 template<typename T, T Val>
379 struct integral_constant
380 {
381 static const T value;
382 typedef T value_type;
383 typedef integral_constant<T, Val> type;
384 operator value_type() { return value; }
385 };
386
387 template<typename T, T Val>
388 const T integral_constant<T, Val>::value = Val;
389
390 typedef integral_constant<bool, true> true_type;
391 typedef integral_constant<bool, false> false_type;
392
393 template<typename T>
394 struct is_trivially_destructible
395 : integral_constant<bool, DISTI_TT_IS_DESTRUCTIBLE( T ) && DISTI_TT_IS_TRIVIALLY_DESTRUCTIBLE( T )>
396 {};
397# endif
398
399} // namespace _cppLangSupportDetail
400} // namespace disti
401#endif
402
403///////////////////////////////////////////////////////////////////////////////////////////////////
404#if defined( DISTI_NO_STATIC_ASSERT )
405# undef DISTI_HAS_STATIC_ASSERT
406# define DISTI_STATIC_ASSERT( expr, msg )
407#else
408 /// Inner macro for preprocessor stringification, do not use this macro directly.
409# define DISTI_PREPROC_STRINGIFY_HELPER( s ) # s
410 /// Use this macro to convert a preprocessor define into a literal string.
411# define DISTI_PREPROC_STRINGIFY( s ) DISTI_PREPROC_STRINGIFY_HELPER( s )
412
413# if defined( DISTI_HAS_STATIC_ASSERT )
414 /// \brief Uses C++11's static_assert() because it is available on this platform.
415 /// \param expr a compile-time integral or pointer expression
416 /// \param msg a C identifier that will appear in compiler diagnostics
417 /// \note For older compilers' benefit, \a msg should be a C identifier such as:
418 /// \code{.cpp}
419 /// DISTI_STATIC_ASSERT( (std::is_convertible<T*,ConvertsTo*>::value), class_does_not_inherit_from_##ConvertsTo )
420 /// \endcode
421 /// which shows a compile-time error that typically includes: "ERROR_class_does_not_inherit_from_Group".
422 /// If it is not a C identifier, you may get spurious error messages at compile time compilers without static_assert.
423# define DISTI_STATIC_ASSERT( expr, msg ) static_assert( expr, DISTI_PREPROC_STRINGIFY( msg ) )
424
425/// \brief Uses C++11's static_assert() because it is available on this platform.
426/// \param expr a compile-time integral or pointer expression with a string message.
427/// \param msg a string to help the developer determine what went wrong.
428/// \code{.cpp}
429/// DISTI_STATIC_ASSERT_STR( (std::is_convertible<T*, Base*>::value), "Class does not inherit from Base." );
430/// \endcode
431/// \note Adapted from Loki 0.1.7.
432# define DISTI_STATIC_ASSERT_STR( expr, msg ) static_assert( expr, msg )
433
434# else
435namespace disti
436{
437namespace _cppLangSupportDetail
438{
439 // Helpers for DISTI_STATIC_ASSERT
440 // \note Adapted from Loki 0.1.7.
441 template<int>
442 struct CompileTimeError;
443
444 /// Helpers for DISTI_STATIC_ASSERT
445 /// \note Adapted from Loki 0.1.7.
446 template<>
447 struct CompileTimeError<true>
448 {
449 CompileTimeError() {}
450 CompileTimeError( const char* ) {}
451 };
452} // namespace _cppLangSupportDetail
453} // namespace disti
454
455/// \brief Poor man's version of C++11's static_assert()
456/// \param expr a compile-time integral or pointer expression
457/// \param msg a C identifier that will appear in compiler diagnostics
458/// \note For older compilers' benefit, \a msg should be a C identifier such as:
459/// \code{.cpp}
460/// DISTI_STATIC_ASSERT( (std::is_convertible<T*, Base*>::value), class_does_not_inherit_from_Base );
461/// \endcode
462/// which shows a compile-time error that typically includes: "ERROR_class_does_not_inherit_from_Base".
463/// If it is not a C identifier, you may get spurious error messages at compile time compilers without static_assert.
464/// \note Adapted from Loki 0.1.7.
465# define DISTI_STATIC_ASSERT( expr, msg ) \
466 { \
467 ::disti::_cppLangSupportDetail::CompileTimeError<( ( expr ) != 0 )> ERROR_##msg; \
468 (void)ERROR_##msg; \
469 }
470
471/// \param expr a compile-time integral or pointer expression with a string message
472/// \param msg a string to help the developer determine what went wrong.
473/// \code{.cpp}
474/// DISTI_STATIC_ASSERT_STR( (std::is_convertible<T*, Base*>::value), "Class does not inherit from Base." );
475/// \endcode
476/// \note Adapted from Loki 0.1.7.
477# define DISTI_STATIC_ASSERT_STR( expr, msg ) \
478 { \
479 ::disti::_cppLangSupportDetail::CompileTimeError<( ( expr ) != 0 )> ERROR_##__LINE__( msg ); \
480 (void)ERROR_##__LINE__; \
481 }
482# endif
483#endif
484
485/// Defines whether this compiler supports the C++14 deprecated attribute.
486#if defined( DISTI_HAS_DEPRECATED_ATTRIBUTE ) && !defined( DISTI_NO_DEPRECATED_ATTRIBUTE )
487# define DISTI_DEPRECATED( msg ) [[deprecated( msg )]]
488#else
489# define DISTI_DEPRECATED( msg )
490#endif
491
492#include <float.h>
493namespace disti
494{
495// clang-format off
496/// \details The MaxDigits10 struct. Since not all platforms support C++11, we provide an equivalent feature here that does not require it.
497/// Formulae derived from the proposal for std::numeric_limits<>::max_digits10 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf)
498template<class T> struct MaxDigits10 { static const unsigned long value = 0; /**< The number of digits.*/ };
499/// \see MaxDigits10
500template<> struct MaxDigits10<float> { static const unsigned long value = 2 + (FLT_MANT_DIG * 30103UL) / 100000UL; /**< The number of digits.*/ };
501/// \see MaxDigits10
502template<> struct MaxDigits10<double> { static const unsigned long value = 2 + (DBL_MANT_DIG * 30103UL) / 100000UL; /**< The number of digits.*/ };
503/// \see MaxDigits10
504template<> struct MaxDigits10<long double> { static const unsigned long value = 2 + (LDBL_MANT_DIG * 30103UL) / 100000UL; /**< The number of digits.*/ };
505// clang-format on
506} // namespace disti
507
508#include <cstdlib>
509#include <typeinfo>
510#if defined( __GNUC__ ) || defined( __clang__ )
511# include <cxxabi.h>
512#endif
513namespace disti
514{
515template<class T>
516
517/// Transforms C++ ABI identifiers into the original C++ source identifiers
518/// \return String containing transformed C++ source identifier.
519/// \pre none
520/// \post none
521const char* Demangle()
522{
523#if defined( __GNUC__ ) || defined( __clang__ )
524 static char* s_unmangledName = NULL;
525 std::free( s_unmangledName );
526
527 // https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
528 int status = 0;
529 s_unmangledName = abi::__cxa_demangle( typeid( T ).name(), NULL, NULL, &status );
530
531 if( 0 == status )
532 {
533 return s_unmangledName;
534 }
535#endif
536 return typeid( T ).name();
537}
538} // namespace disti
539
540#endif
Definition: bmpimage.h:46
const char * Demangle()
Definition: gls_cpp_lang_support.h:521
Definition: gls_cpp_lang_support.h:498
static const unsigned long value
Definition: gls_cpp_lang_support.h:498