Skip to content

Commit fea85aa

Browse files
committed
First step of simplifying compiler checks
There is more that can be done but each removal of a #DEFINE needs to check exactly where it is used. The bottom part of compiler.h still spans a grid over C++0x/TR1 to see if unordered map and set are a given (as in C++11 or later) which together with other calls of 'C++11 it is now' can simplify but we need to carefully walk this through the rest of the code and not just delete here as we'd keep unnecessary #define 'orphans' around.
1 parent 34997ab commit fea85aa

File tree

2 files changed

+54
-82
lines changed

2 files changed

+54
-82
lines changed

inst/include/Rcpp/platform/compiler.h

Lines changed: 49 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
//
31
// compiler.h: Rcpp R/C++ interface class library -- check compiler
42
//
5-
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey
3+
// Copyright (C) 2012 - 2025 Dirk Eddelbuettel, Romain Francois, and Kevin Ushey
64
//
75
// This file is part of Rcpp.
86
//
@@ -43,99 +41,72 @@
4341
# error "This compiler is not supported"
4442
#endif
4543

44+
#if __cplusplus < 201103L
45+
# error "The C++ compilation standard is too old: use C++11 or newer."
46+
#endif
47+
4648
#ifdef __GNUC__
4749
#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
5950
#endif
6051

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
52+
// TODO: Clean in a subsequent round
53+
#define RCPP_USING_CXX0X_OR_LATER
6554

66-
// Check C++0x/11 features
55+
// Check C++11 features (could/should work generally)
6756
#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
57+
#define RCPP_USING_CXX11
58+
#if __INTEL_COMPILER >= 1210
59+
#define HAS_VARIADIC_TEMPLATES
60+
#endif
61+
#if __INTEL_COMPILER >= 1100
62+
#define HAS_STATIC_ASSERT
7663
#endif
7764
#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
65+
#define RCPP_USING_CXX11
66+
#if __has_feature(cxx_variadic_templates)
67+
#define HAS_VARIADIC_TEMPLATES
68+
#endif
69+
#if __has_feature(cxx_static_assert)
70+
#define HAS_STATIC_ASSERT
8671
#endif
8772
#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
73+
#define RCPP_USING_CXX11
74+
#if __has_feature(cxx_variadic_templates)
75+
#define HAS_VARIADIC_TEMPLATES
76+
#endif
77+
#if __has_feature(cxx_static_assert)
78+
#define HAS_STATIC_ASSERT
9379
#endif
94-
#if GCC_VERSION >= 40800 && __cplusplus >= 201103L
95-
#define RCPP_USING_CXX11
96-
#endif
9780
#endif
9881

99-
// Check C++0x headers
82+
// Check C++0x headers (TODO remove when no longer needed below)
10083
#include <cmath>
10184
#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
85+
#define HAS_CXX0X_UNORDERED_MAP
86+
#define HAS_CXX0X_UNORDERED_SET
87+
#define HAS_CXX0X_INITIALIZER_LIST
10988
#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
89+
#if __has_include(<unordered_map>)
90+
#define HAS_CXX0X_UNORDERED_MAP
91+
#endif
92+
#if __has_include(<unordered_set>)
93+
#define HAS_CXX0X_UNORDERED_SET
94+
#endif
95+
#if __has_include(<initializer_list>)
96+
#define HAS_CXX0X_INITIALIZER_LIST
12097
#endif
12198
#endif
12299

123-
// Check TR1 Headers
100+
// Check TR1 Headers (TODO remove when no longer needed below)
124101
#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
102+
#define HAS_TR1_UNORDERED_MAP
103+
#define HAS_TR1_UNORDERED_SET
131104
#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
105+
#if __has_include(<tr1/unordered_map>)
106+
#define HAS_TR1_UNORDERED_MAP
107+
#endif
108+
#if __has_include(<tr1/unordered_set>)
109+
#define HAS_TR1_UNORDERED_SET
139110
#endif
140111
#endif
141112

@@ -144,10 +115,11 @@
144115
#endif
145116

146117
// Conditionally include headers
147-
#ifdef HAS_CXX0X_INITIALIZER_LIST
118+
// #ifdef HAS_CXX0X_INITIALIZER_LIST
148119
#include <initializer_list>
149-
#endif
120+
// #endif
150121

122+
// TODO: Simplify further: First case should work generally
151123
#ifdef RCPP_USING_CXX11
152124
#if defined(HAS_CXX0X_UNORDERED_MAP)
153125
#include <unordered_map>

inst/include/Rcpp/sugar/functions/sapply.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
#ifndef Rcpp__sugar__sapply_h
2222
#define Rcpp__sugar__sapply_h
2323

24-
#if defined(RCPP_USING_CXX0X_OR_LATER)
25-
#include <type_traits> // ::std::result_of
26-
#endif
24+
// This used to be conditional on a define and test in compiler.h
25+
#include <type_traits> // ::std::result_of
2726

2827
namespace Rcpp{
2928
namespace sugar{
3029

3130
template <typename Function, typename SugarExpression>
3231
struct sapply_application_result_of
3332
{
34-
#if defined(RCPP_USING_CXX0X_OR_LATER)
33+
#if __cplusplus >= 201103L
3534
#if __cplusplus < 201703L
3635
// deprecated by C++17, removed by C++2020, see https://en.cppreference.com/w/cpp/types/result_of
3736
typedef typename ::std::result_of<Function(typename SugarExpression::stored_type)>::type type;
@@ -40,9 +39,10 @@ struct sapply_application_result_of
4039
typedef typename ::std::invoke_result<Function, typename SugarExpression::stored_type>::type type;
4140
#endif
4241
#else
42+
// TODO this else branch can likely go
4343
typedef typename ::Rcpp::traits::result_of<Function>::type type;
4444
#endif
45-
} ;
45+
};
4646

4747
// template <typename Function, typename SugarExpression>
4848
// using sapply_application_result_of_t = typename sapply_application_result_of<Function, SugarExpression>::type;

0 commit comments

Comments
 (0)