Rcpp Version 0.12.12
compiler.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // compiler.h: Rcpp R/C++ interface class library -- check compiler
4 //
5 // Copyright (C) 2012 - 2013 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp__platform__compiler_h
23 #define Rcpp__platform__compiler_h
24 
25 // NB: A vast list valid identifiers is at these wiki pages:
26 // http://sourceforge.net/p/predef/wiki/Home/
27 
28 #undef GOOD_COMPILER_FOR_RCPP
29 #ifdef __GNUC__
30 #define GOOD_COMPILER_FOR_RCPP
31 #endif
32 #ifdef __SUNPRO_CC
33 #define GOOD_COMPILER_FOR_RCPP
34 #endif
35 #ifdef __clang__
36 #define GOOD_COMPILER_FOR_RCPP
37 #endif
38 #ifdef __INTEL_COMPILER
39 #define GOOD_COMPILER_FOR_RCPP
40 #endif
41 
42 #ifndef GOOD_COMPILER_FOR_RCPP
43 # error "This compiler is not supported"
44 #endif
45 
46 #ifdef __GNUC__
47  #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
48  // g++ 4.5 does not seem to like some of the fast indexing
49  #if GCC_VERSION >= 40500
50  #define IS_GCC_450_OR_LATER
51  #endif
52  // g++ 4.6 switches from exception_defines.h to bits/exception_defines.h
53  #if GCC_VERSION < 40600
54  #define IS_EARLIER_THAN_GCC_460
55  #endif
56  #if GCC_VERSION >= 40600
57  #define IS_GCC_460_OR_LATER
58  #endif
59 #endif
60 
61 // Check for the presence of C++0x (or later) support
62 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
63  #define RCPP_USING_CXX0X_OR_LATER
64 #endif
65 
66 // Check C++0x/11 features
67 #if defined(__INTEL_COMPILER)
68  #if __cplusplus >= 201103L
69  #define RCPP_USING_CXX11
70  #if __INTEL_COMPILER >= 1210
71  // #define HAS_VARIADIC_TEMPLATES
72  #endif
73  #if __INTEL_COMPILER >= 1100
74  #define HAS_STATIC_ASSERT
75  #endif
76  #endif
77 #elif defined(__clang__)
78  #if __cplusplus >= 201103L
79  #define RCPP_USING_CXX11
80  #if __has_feature(cxx_variadic_templates)
81  // #define HAS_VARIADIC_TEMPLATES
82  #endif
83  #if __has_feature(cxx_static_assert)
84  #define HAS_STATIC_ASSERT
85  #endif
86  #endif
87 #elif defined(__GNUC__)
88  #ifdef __GXX_EXPERIMENTAL_CXX0X__
89  #if GCC_VERSION >= 40300
90  // #define HAS_VARIADIC_TEMPLATES
91  #define HAS_STATIC_ASSERT
92  #endif
93  #endif
94  #if GCC_VERSION >= 40800 && __cplusplus >= 201103L
95  #define RCPP_USING_CXX11
96  #endif
97 #endif
98 
99 // Check C++0x headers
100 #include <cmath>
101 #if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__))
102  #if defined(__GLIBCXX__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
103  #if GCC_VERSION >= 40400
104  #define HAS_CXX0X_UNORDERED_MAP
105  #define HAS_CXX0X_UNORDERED_SET
106  #define HAS_CXX0X_INITIALIZER_LIST
107  #endif
108  #endif
109 #elif defined(__clang__)
110  #if __cplusplus >= 201103L
111  #if __has_include(<unordered_map>)
112  #define HAS_CXX0X_UNORDERED_MAP
113  #endif
114  #if __has_include(<unordered_set>)
115  #define HAS_CXX0X_UNORDERED_SET
116  #endif
117  #if __has_include(<initializer_list>)
118  #define HAS_CXX0X_INITIALIZER_LIST
119  #endif
120  #endif
121 #endif
122 
123 // Check TR1 Headers
124 #if defined(__INTEL_COMPILER) || (defined(__GNUC__) && !defined(__clang__))
125  #if defined(__GLIBCXX__)
126  #if GCC_VERSION >= 40400 || ( GCC_VERSION >= 40201 && defined(__APPLE__) )
127  #define HAS_TR1_UNORDERED_MAP
128  #define HAS_TR1_UNORDERED_SET
129  #endif
130  #endif
131 #elif defined(__clang__)
132  #if __cplusplus >= 201103L
133  #if __has_include(<tr1/unordered_map>)
134  #define HAS_TR1_UNORDERED_MAP
135  #endif
136  #if __has_include(<tr1/unordered_set>)
137  #define HAS_TR1_UNORDERED_SET
138  #endif
139  #endif
140 #endif
141 
142 #if defined(HAS_TR1_UNORDERED_MAP) && defined(HAS_TR1_UNORDERED_SET)
143 #define HAS_TR1
144 #endif
145 
146 // Conditionally include headers
147 #ifdef HAS_CXX0X_INITIALIZER_LIST
148 #include <initializer_list>
149 #endif
150 
151 #ifdef RCPP_USING_CXX11
152  #if defined(HAS_CXX0X_UNORDERED_MAP)
153  #include <unordered_map>
154  #define RCPP_USING_UNORDERED_MAP
155  #define RCPP_UNORDERED_MAP std::unordered_map
156  #else
157  #include <map>
158  #define RCPP_USING_MAP
159  #define RCPP_UNORDERED_MAP std::map
160  #endif
161  #if defined(HAS_CXX0X_UNORDERED_SET)
162  #include <unordered_set>
163  #define RCPP_USING_UNORDERED_SET
164  #define RCPP_UNORDERED_SET std::unordered_set
165  #else
166  #include <set>
167  #define RCPP_USING_SET
168  #define RCPP_UNORDERED_SET std::set
169  #endif
170 #else
171  #if defined(HAS_TR1_UNORDERED_MAP)
172  #include <tr1/unordered_map>
173  #define RCPP_USING_TR1_UNORDERED_MAP
174  #define RCPP_UNORDERED_MAP std::tr1::unordered_map
175  #else
176  #include <map>
177  #define RCPP_USING_MAP
178  #define RCPP_UNORDERED_MAP std::map
179  #endif
180  #if defined(HAS_TR1_UNORDERED_SET)
181  #include <tr1/unordered_set>
182  #define RCPP_USING_TR1_UNORDERED_SET
183  #define RCPP_UNORDERED_SET std::tr1::unordered_set
184  #else
185  #include <set>
186  #define RCPP_USING_SET
187  #define RCPP_UNORDERED_SET std::set
188  #endif
189 #endif
190 
191 #ifdef __GNUC__
192  #define RCPP_HAS_DEMANGLING
193 #endif
194 
195 
196 #endif