Skip to content

Commit

Permalink
Extending C++11 header to allow detection of initializer lists and nu…
Browse files Browse the repository at this point in the history
…llptr_t
  • Loading branch information
codemercenary committed Aug 20, 2014
1 parent 959a4e7 commit 9bd5af0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 50 additions & 1 deletion contrib/C++11/cpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define STL11_ALLOWED 1
#endif

#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)

Expand Down Expand Up @@ -43,6 +44,21 @@
#define STL_UNORDERED_MAP <unordered_map>
#endif

/*********************
* initializer_list header
*********************/
#if IS_CLANG
#define HAS_INITIALIZER_LIST __has_include(<initializer_list>) && __has_feature(cxx_generalized_initializers)
#if HAS_INITIALIZER_LIST
#define INITIALIZER_LIST_HEADER <initializer_list>
#else
#define INITIALIZER_LIST_HEADER <contrib/C++11/empty_file.h>
#endif
#else
#define HAS_INITIALIZER_LIST 1
#define INITIALIZER_LIST_HEADER <initializer_list>
#endif

/*********************
* Check override keyword availability
*********************/
Expand All @@ -66,6 +82,10 @@
#define static_assert(...)
#endif

#if defined(_MSC_VER) || !IS_CLANG
#define AUTOWIRE_cxx_override_control 1
#endif

/*********************
* exception_ptr availability
*********************/
Expand Down Expand Up @@ -129,7 +149,7 @@
* Decide what version of shared_ptr we are going to use
*********************/

// Nullptr available in VS10
// Shared pointer available in VS10
#if _MSC_VER >= 1500
#define SHARED_PTR_IN_STL 1
#elif __cplusplus > 199711L || __GXX_EXPERIMENTAL_CXX0X__
Expand All @@ -144,6 +164,35 @@
#define MEMORY_HEADER <contrib/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 0
#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
*********************/
Expand Down
2 changes: 2 additions & 0 deletions contrib/C++11/empty_file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
// Just an empty file, used when we cannot provide a feature.

0 comments on commit 9bd5af0

Please sign in to comment.