Skip to content

Commit 72a91b6

Browse files
committed
Merge pull request #166 from cauthmann/std11detection
Std11detection
2 parents 8816c7c + 44975ef commit 72a91b6

File tree

8 files changed

+36
-17
lines changed

8 files changed

+36
-17
lines changed

inst/NEWS.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
\item Changes in Rcpp API:
88
\itemize{
99
\item New \code{Rcpp::InternalFunction} interface using
10-
\code{std::function}; it needs a \code{define} for \code{RCPP_USE_STD_FUNCTION}
11-
as sufficiently feature-rich C++11 implemented is needed.
10+
\code{std::function}; only enabled on compilers that claim full c++11
11+
support.
1212
\item The deprecation of \code{RCPP_FUNCTION_*} which was announced with
1313
release 0.10.5 last year is proceeding as planned, and the file
1414
\code{macros/preprocessor_generated.h} has been removed.

inst/include/Rcpp/InternalFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <Rcpp/grow.h>
2828

29-
#ifdef RCPP_USE_STD_FUNCTION
29+
#ifdef RCPP_USING_CXX11
3030
#include <Rcpp/InternalFunctionWithStdFunction.h>
3131
#endif
3232

@@ -37,7 +37,7 @@ namespace Rcpp{
3737

3838
RCPP_GENERATE_CTOR_ASSIGN(InternalFunction_Impl)
3939

40-
#ifdef RCPP_USE_STD_FUNCTION
40+
#ifdef RCPP_USING_CXX11
4141
template <typename RESULT_TYPE, typename... Args>
4242
InternalFunction_Impl(const std::function<RESULT_TYPE(Args...)> &fun) {
4343
set(

inst/include/Rcpp/platform/compiler.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
#endif
5959
#endif
6060

61-
// Check C++0x features
61+
// Check C++0x/11 features
6262
#if defined(__INTEL_COMPILER)
6363
#if __cplusplus >= 201103L
64-
#define HAS_CXX0X_FLAG
64+
#define RCPP_USING_CXX11
6565
#if __INTEL_COMPILER >= 1210
6666
// #define HAS_VARIADIC_TEMPLATES
6767
#endif
@@ -71,7 +71,7 @@
7171
#endif
7272
#elif defined(__clang__)
7373
#if __cplusplus >= 201103L
74-
#define HAS_CXX0X_FLAG
74+
#define RCPP_USING_CXX11
7575
#if __has_feature(cxx_variadic_templates)
7676
// #define HAS_VARIADIC_TEMPLATES
7777
#endif
@@ -81,12 +81,14 @@
8181
#endif
8282
#elif defined(__GNUC__)
8383
#ifdef __GXX_EXPERIMENTAL_CXX0X__
84-
// #define HAS_CXX0X_FLAG
8584
#if GCC_VERSION >= 40300
8685
// #define HAS_VARIADIC_TEMPLATES
8786
#define HAS_STATIC_ASSERT
8887
#endif
8988
#endif
89+
#if GCC_VERSION >= 40800 && __cplusplus >= 201103L
90+
#define RCPP_USING_CXX11
91+
#endif
9092
#endif
9193

9294
// Check C++0x headers
@@ -141,7 +143,7 @@
141143
#include <initializer_list>
142144
#endif
143145

144-
#ifdef HAS_CXX0X_FLAG
146+
#ifdef RCPP_USING_CXX11
145147
#if defined(HAS_CXX0X_UNORDERED_MAP)
146148
#include <unordered_map>
147149
#define RCPP_USING_UNORDERED_MAP
@@ -185,4 +187,5 @@
185187
#define RCPP_HAS_DEMANGLING
186188
#endif
187189

190+
188191
#endif

inst/unitTests/cpp/InternalFunctionCPP11.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
2121

2222

23-
#define RCPP_USE_STD_FUNCTION
2423
#include <Rcpp.h>
2524

2625

inst/unitTests/runit.InternalFunctionCPP11.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
# You should have received a copy of the GNU General Public License
1919
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
2020

21-
hasCXX11 <- grepl("-std=c\\+\\+1[1-9yz]", Sys.getenv("PKG_CXXFLAGS"))
21+
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
2222

23-
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" && hasCXX11
24-
25-
if( .runThisTest ) {
23+
if( .runThisTest && Rcpp:::capabilities()[["Full C++11 support"]] ) {
2624

2725
.tearDown <- function(){
2826
gc()

src/Rcpp_init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static R_CallMethodDef callEntries[] = {
5656

5757
CALLDEF(rcpp_capabilities,0),
5858
CALLDEF(rcpp_can_use_cxx0x,0),
59+
CALLDEF(rcpp_can_use_cxx11,0),
5960
{NULL, NULL, 0}
6061
};
6162

src/api.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ SEXP as_character_externalptr(SEXP xp){
155155

156156
// [[Rcpp::internal]]
157157
SEXP rcpp_capabilities(){
158-
Shield<SEXP> cap( Rf_allocVector( LGLSXP, 11 ) );
159-
Shield<SEXP> names( Rf_allocVector( STRSXP, 11 ) );
158+
Shield<SEXP> cap( Rf_allocVector( LGLSXP, 12 ) );
159+
Shield<SEXP> names( Rf_allocVector( STRSXP, 12 ) );
160160
#ifdef HAS_VARIADIC_TEMPLATES
161161
LOGICAL(cap)[0] = TRUE ;
162162
#else
@@ -210,6 +210,12 @@ SEXP rcpp_capabilities(){
210210
LOGICAL(cap)[10] = FALSE ;
211211
#endif
212212

213+
#ifdef RCPP_USING_CXX11
214+
LOGICAL(cap)[11] = TRUE ;
215+
#else
216+
LOGICAL(cap)[11] = FALSE ;
217+
#endif
218+
213219
SET_STRING_ELT(names, 0, Rf_mkChar("variadic templates") ) ;
214220
SET_STRING_ELT(names, 1, Rf_mkChar("initializer lists") ) ;
215221
SET_STRING_ELT(names, 2, Rf_mkChar("exception handling") ) ;
@@ -221,14 +227,25 @@ SEXP rcpp_capabilities(){
221227
SET_STRING_ELT(names, 8, Rf_mkChar("long long") ) ;
222228
SET_STRING_ELT(names, 9, Rf_mkChar("C++0x unordered maps") ) ;
223229
SET_STRING_ELT(names, 10, Rf_mkChar("C++0x unordered sets") ) ;
230+
SET_STRING_ELT(names, 11, Rf_mkChar("Full C++11 support") ) ;
224231
Rf_setAttrib( cap, R_NamesSymbol, names ) ;
225232
return cap ;
226233
}
227234

228235

229236
// [[Rcpp::internal]]
230237
SEXP rcpp_can_use_cxx0x(){
231-
#ifdef HAS_VARIADIC_TEMPLATES
238+
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
239+
return Rf_ScalarLogical( TRUE );
240+
#else
241+
return Rf_ScalarLogical( FALSE );
242+
#endif
243+
}
244+
245+
246+
// [[Rcpp::internal]]
247+
SEXP rcpp_can_use_cxx11(){
248+
#if defined(RCPP_USING_CXX11)
232249
return Rf_ScalarLogical( TRUE );
233250
#else
234251
return Rf_ScalarLogical( FALSE );

src/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ CALLFUN_4(CppField__set);
120120

121121
CALLFUN_0(rcpp_capabilities) ;
122122
CALLFUN_0(rcpp_can_use_cxx0x) ;
123+
CALLFUN_0(rcpp_can_use_cxx11) ;
123124

124125
/* .External functions */
125126
EXTFUN(CppMethod__invoke) ;

0 commit comments

Comments
 (0)