22//
33// algorithm.h: Rcpp R/C++ interface class library -- data frames
44//
5- // Copyright (C) 2016 - 2017 Daniel C. Dillon
5+ // Copyright (C) 2016 - 2024 Daniel C. Dillon
6+ // Copyright (C) 2025 Daniel C. Dillon and Iñaki Ucar
67//
78// This file is part of Rcpp.
89//
2223#ifndef Rcpp__Algorithm_h
2324#define Rcpp__Algorithm_h
2425
25- #if __cplusplus >= 201103L || __INTEL_CXX11_MODE__ == 1
26- # define RCPP_CONSTEXPR_FUNC constexpr
27- # define RCPP_CONSTEXPR_VAR constexpr
28- #else
29- # define RCPP_CONSTEXPR_FUNC
30- # define RCPP_CONSTEXPR_VAR const
31- #endif
32-
3326namespace Rcpp {
3427namespace algorithm {
3528
@@ -38,9 +31,7 @@ namespace helpers {
3831 typedef struct {char a[2 ];} CTYPE_SHORT;
3932 typedef struct {char a[3 ];} CTYPE_INT;
4033 typedef struct {char a[4 ];} CTYPE_LONG;
41- #ifdef RCPP_HAS_LONG_LONG_TYPES
4234 typedef struct {char a[5 ];} CTYPE_LONG_LONG;
43- #endif
4435 typedef struct {char a[6 ];} CTYPE_FLOAT;
4536 typedef struct {char a[7 ];} CTYPE_DOUBLE;
4637 typedef struct {char a[8 ];} CTYPE_LONG_DOUBLE;
@@ -49,9 +40,7 @@ namespace helpers {
4940 typedef struct {char a[11 ];} CTYPE_UNSIGNED_SHORT;
5041 typedef struct {char a[12 ];} CTYPE_UNSIGNED_INT;
5142 typedef struct {char a[13 ];} CTYPE_UNSIGNED_LONG;
52- #ifdef RCPP_HAS_LONG_LONG_TYPES
5343 typedef struct {char a[14 ];} CTYPE_UNSIGNED_LONG_LONG;
54- #endif
5544 typedef struct {char a[128 ];} CTYPE_UNKNOWN;
5645
5746 template < std::size_t I >
@@ -69,10 +58,8 @@ namespace helpers {
6958 template <>
7059 struct ctype_helper < sizeof (CTYPE_LONG) > { typedef long type; static const bool value = true ; };
7160
72- #ifdef RCPP_HAS_LONG_LONG_TYPES
7361 template <>
7462 struct ctype_helper < sizeof (CTYPE_LONG_LONG) > { typedef rcpp_long_long_type type; static const bool value = true ; };
75- #endif
7663
7764 template <>
7865 struct ctype_helper < sizeof (CTYPE_FLOAT) > { typedef float type; static const bool value = true ; };
@@ -98,11 +85,8 @@ namespace helpers {
9885 template <>
9986 struct ctype_helper < sizeof (CTYPE_UNSIGNED_LONG) > { typedef unsigned long type; static const bool value = true ; };
10087
101- #ifdef RCPP_HAS_LONG_LONG_TYPES
10288 template <>
10389 struct ctype_helper < sizeof (CTYPE_UNSIGNED_LONG_LONG) > { typedef rcpp_ulong_long_type type; static const bool value = true ; };
104- #endif
105-
10690
10791 template < typename T >
10892 struct ctype
@@ -111,9 +95,7 @@ namespace helpers {
11195 static CTYPE_SHORT test (const short &);
11296 static CTYPE_INT test (const int &);
11397 static CTYPE_LONG test (const long &);
114- #ifdef RCPP_HAS_LONG_LONG_TYPES
11598 static CTYPE_LONG_LONG test (const rcpp_long_long_type &);
116- #endif
11799 static CTYPE_FLOAT test (const float &);
118100 static CTYPE_DOUBLE test (const double &);
119101 static CTYPE_LONG_DOUBLE test (const long double &);
@@ -122,9 +104,7 @@ namespace helpers {
122104 static CTYPE_UNSIGNED_SHORT test (const unsigned short &);
123105 static CTYPE_UNSIGNED_INT test (const unsigned int &);
124106 static CTYPE_UNSIGNED_LONG test (const unsigned long &);
125- #ifdef RCPP_HAS_LONG_LONG_TYPES
126107 static CTYPE_UNSIGNED_LONG_LONG test (const rcpp_ulong_long_type &);
127- #endif
128108 static CTYPE_UNKNOWN test (...);
129109
130110 static T make ();
@@ -139,9 +119,7 @@ namespace helpers {
139119 static CTYPE_SHORT test (const short &);
140120 static CTYPE_INT test (const int &);
141121 static CTYPE_LONG test (const long &);
142- #ifdef RCPP_HAS_LONG_LONG_TYPES
143122 static CTYPE_LONG_LONG test (const rcpp_long_long_type &);
144- #endif
145123 static CTYPE_FLOAT test (const float &);
146124 static CTYPE_DOUBLE test (const double &);
147125 static CTYPE_LONG_DOUBLE test (const long double &);
@@ -150,9 +128,7 @@ namespace helpers {
150128 static CTYPE_UNSIGNED_SHORT test (const unsigned short &);
151129 static CTYPE_UNSIGNED_INT test (const unsigned int &);
152130 static CTYPE_UNSIGNED_LONG test (const unsigned long &);
153- #ifdef RCPP_HAS_LONG_LONG_TYPES
154131 static CTYPE_UNSIGNED_LONG_LONG test (const rcpp_ulong_long_type &);
155- #endif
156132 static CTYPE_UNKNOWN test (...);
157133
158134 static T make ();
@@ -167,29 +143,29 @@ namespace helpers {
167143 template <>
168144 struct rtype_helper < double > {
169145 typedef double type;
170- static RCPP_CONSTEXPR_VAR int RTYPE = REALSXP;
146+ static constexpr int RTYPE = REALSXP;
171147 static inline double NA () { return NA_REAL; }
172- static inline RCPP_CONSTEXPR_FUNC double ZERO () { return 0.0 ; }
173- static inline RCPP_CONSTEXPR_FUNC double ONE () { return 1.0 ; }
148+ static inline constexpr double ZERO () { return 0.0 ; }
149+ static inline constexpr double ONE () { return 1.0 ; }
174150 };
175151
176152 template <>
177153 struct rtype_helper < int > {
178154 typedef int type;
179- static RCPP_CONSTEXPR_VAR int RTYPE = INTSXP;
155+ static constexpr int RTYPE = INTSXP;
180156 static inline int NA () { return NA_INTEGER; }
181- static inline RCPP_CONSTEXPR_FUNC int ZERO () { return 0 ; }
182- static inline RCPP_CONSTEXPR_FUNC int ONE () { return 1 ; }
157+ static inline constexpr int ZERO () { return 0 ; }
158+ static inline constexpr int ONE () { return 1 ; }
183159 };
184160
185161 template < typename T >
186162 struct rtype {
187163 typedef typename rtype_helper< typename ctype< T >::type >::type type;
188164 typedef rtype_helper< typename ctype< T >::type > helper_type;
189- static RCPP_CONSTEXPR_VAR int RTYPE = helper_type::RTYPE;
165+ static constexpr int RTYPE = helper_type::RTYPE;
190166 static inline T NA () { return helper_type::NA (); }
191- static inline RCPP_CONSTEXPR_FUNC T ZERO () { return helper_type::ZERO (); }
192- static inline RCPP_CONSTEXPR_FUNC T ONE () { return helper_type::ONE (); }
167+ static inline constexpr T ZERO () { return helper_type::ZERO (); }
168+ static inline constexpr T ONE () { return helper_type::ONE (); }
193169 };
194170
195171 struct log {
@@ -483,7 +459,4 @@ void sqrt(InputIterator begin, InputIterator end, OutputIterator out) {
483459} // namespace algorithm
484460} // namespace Rcpp
485461
486- #undef RCPP_CONSTEXPR_FUNC
487- #undef RCPP_CONSTEXPR_VAR
488-
489462#endif
0 commit comments