Skip to content

Cleanup __cplusplus checks #1371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
2025-03-24 Iñaki Ucar <iucar@fedoraproject.org>

* inst/include/Rcpp/exceptions.h: Include C+11 variadic template definitions
unconditionally
* inst/include/Rcpp/exceptions/cpp11/exceptions.h: Removed
* inst/include/Rcpp/exceptions/cpp98/exceptions.h: Idem

* src/attributes.cpp: Remove obsolete pre-C+11 paths based on __cplusplus
define checks
* inst/tinytest/cpp/sugar.cpp: Idem
* inst/include/Rcpp/Language.h: Idem
* inst/include/Rcpp/StringTransformer.h: Idem
* inst/include/Rcpp/algorithm.h: Idem
* inst/include/Rcpp/utils/tinyformat.h: Idem
* inst/include/Rcpp/longlong.h: Idem, unconditional RCPP_HAS_LONG_LONG_TYPES

* src/api.cpp: Remove explicit RCPP_HAS_LONG_LONG_TYPES as availability is
both implicit and ensured
* inst/include/Rcpp/algorithm.h: Idem
* inst/include/Rcpp/traits/is_arithmetic.h: Idem
* inst/include/Rcpp/traits/longlong.h: Idem

2025-03-21 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll micro version and date
* inst/include/Rcpp/config.h: Idem

* inst/include/Rcpp/String.h: Remove explicit RCPP_USING_CXX11 as
use of C++11 (or newer) is both implicit and ensuredIdem
use of C++11 (or newer) is both implicit and ensured
* inst/include/Rcpp/macros/dispatch.h: Idem
* inst/include/Rcpp/platform/compiler.h: Idem
* inst/include/Rcpp/unwindProtect.h: Idem
8 changes: 0 additions & 8 deletions inst/include/Rcpp/Language.h
Original file line number Diff line number Diff line change
@@ -186,11 +186,7 @@ namespace Rcpp{
};

template <typename T, typename RESULT_TYPE = SEXP>
#if __cplusplus < 201103L
class unary_call : public std::unary_function<T,RESULT_TYPE> {
#else
class unary_call : public std::function<RESULT_TYPE(T)> {
#endif
public:
unary_call( Language call_ ) : call(call_), proxy(call_,1) {}
unary_call( Language call_, R_xlen_t index ) : call(call_), proxy(call_,index){}
@@ -207,11 +203,7 @@ namespace Rcpp{
};

template <typename T1, typename T2, typename RESULT_TYPE = SEXP>
#if __cplusplus < 201103L
class binary_call : public std::binary_function<T1,T2,RESULT_TYPE> {
#else
class binary_call : public std::function<RESULT_TYPE(T1,T2)> {
#endif
public:
binary_call( Language call_ ) : call(call_), proxy1(call_,1), proxy2(call_,2) {}
binary_call( Language call_, R_xlen_t index1, R_xlen_t index2 ) : call(call_), proxy1(call_,index1), proxy2(call_,index2){}
6 changes: 1 addition & 5 deletions inst/include/Rcpp/StringTransformer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// clone.h: Rcpp R/C++ interface class library -- clone RObject's
//
// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -26,11 +26,7 @@
namespace Rcpp{

template <typename UnaryOperator>
#if __cplusplus < 201103L
class StringTransformer : public std::unary_function<const char*, const char*> {
#else
class StringTransformer : public std::function<const char*(const char*)> {
#endif
public:
StringTransformer( const UnaryOperator& op_ ): op(op_), buffer(){}
~StringTransformer(){}
49 changes: 11 additions & 38 deletions inst/include/Rcpp/algorithm.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
//
// algorithm.h: Rcpp R/C++ interface class library -- data frames
//
// Copyright (C) 2016 - 2017 Daniel C. Dillon
// Copyright (C) 2016 - 2024 Daniel C. Dillon
// Copyright (C) 2025 Daniel C. Dillon and Iñaki Ucar
//
// This file is part of Rcpp.
//
@@ -22,14 +23,6 @@
#ifndef Rcpp__Algorithm_h
#define Rcpp__Algorithm_h

#if __cplusplus >= 201103L || __INTEL_CXX11_MODE__ == 1
# define RCPP_CONSTEXPR_FUNC constexpr
# define RCPP_CONSTEXPR_VAR constexpr
#else
# define RCPP_CONSTEXPR_FUNC
# define RCPP_CONSTEXPR_VAR const
#endif

namespace Rcpp {
namespace algorithm {

@@ -38,9 +31,7 @@ namespace helpers {
typedef struct {char a[2];} CTYPE_SHORT;
typedef struct {char a[3];} CTYPE_INT;
typedef struct {char a[4];} CTYPE_LONG;
#ifdef RCPP_HAS_LONG_LONG_TYPES
typedef struct {char a[5];} CTYPE_LONG_LONG;
#endif
typedef struct {char a[6];} CTYPE_FLOAT;
typedef struct {char a[7];} CTYPE_DOUBLE;
typedef struct {char a[8];} CTYPE_LONG_DOUBLE;
@@ -49,9 +40,7 @@ namespace helpers {
typedef struct {char a[11];} CTYPE_UNSIGNED_SHORT;
typedef struct {char a[12];} CTYPE_UNSIGNED_INT;
typedef struct {char a[13];} CTYPE_UNSIGNED_LONG;
#ifdef RCPP_HAS_LONG_LONG_TYPES
typedef struct {char a[14];} CTYPE_UNSIGNED_LONG_LONG;
#endif
typedef struct {char a[128];} CTYPE_UNKNOWN;

template< std::size_t I >
@@ -69,10 +58,8 @@ namespace helpers {
template<>
struct ctype_helper< sizeof(CTYPE_LONG) > { typedef long type; static const bool value = true; };

#ifdef RCPP_HAS_LONG_LONG_TYPES
template<>
struct ctype_helper< sizeof(CTYPE_LONG_LONG) > { typedef rcpp_long_long_type type; static const bool value = true; };
#endif

template<>
struct ctype_helper< sizeof(CTYPE_FLOAT) > { typedef float type; static const bool value = true; };
@@ -98,11 +85,8 @@ namespace helpers {
template<>
struct ctype_helper< sizeof(CTYPE_UNSIGNED_LONG) > { typedef unsigned long type; static const bool value = true; };

#ifdef RCPP_HAS_LONG_LONG_TYPES
template<>
struct ctype_helper< sizeof(CTYPE_UNSIGNED_LONG_LONG) > { typedef rcpp_ulong_long_type type; static const bool value = true; };
#endif


template< typename T >
struct ctype
@@ -111,9 +95,7 @@ namespace helpers {
static CTYPE_SHORT test(const short &);
static CTYPE_INT test(const int &);
static CTYPE_LONG test(const long &);
#ifdef RCPP_HAS_LONG_LONG_TYPES
static CTYPE_LONG_LONG test(const rcpp_long_long_type &);
#endif
static CTYPE_FLOAT test(const float &);
static CTYPE_DOUBLE test(const double &);
static CTYPE_LONG_DOUBLE test(const long double &);
@@ -122,9 +104,7 @@ namespace helpers {
static CTYPE_UNSIGNED_SHORT test(const unsigned short &);
static CTYPE_UNSIGNED_INT test(const unsigned int &);
static CTYPE_UNSIGNED_LONG test(const unsigned long &);
#ifdef RCPP_HAS_LONG_LONG_TYPES
static CTYPE_UNSIGNED_LONG_LONG test(const rcpp_ulong_long_type &);
#endif
static CTYPE_UNKNOWN test(...);

static T make();
@@ -139,9 +119,7 @@ namespace helpers {
static CTYPE_SHORT test(const short &);
static CTYPE_INT test(const int &);
static CTYPE_LONG test(const long &);
#ifdef RCPP_HAS_LONG_LONG_TYPES
static CTYPE_LONG_LONG test(const rcpp_long_long_type &);
#endif
static CTYPE_FLOAT test(const float &);
static CTYPE_DOUBLE test(const double &);
static CTYPE_LONG_DOUBLE test(const long double &);
@@ -150,9 +128,7 @@ namespace helpers {
static CTYPE_UNSIGNED_SHORT test(const unsigned short &);
static CTYPE_UNSIGNED_INT test(const unsigned int &);
static CTYPE_UNSIGNED_LONG test(const unsigned long &);
#ifdef RCPP_HAS_LONG_LONG_TYPES
static CTYPE_UNSIGNED_LONG_LONG test(const rcpp_ulong_long_type &);
#endif
static CTYPE_UNKNOWN test(...);

static T make();
@@ -167,29 +143,29 @@ namespace helpers {
template<>
struct rtype_helper< double > {
typedef double type;
static RCPP_CONSTEXPR_VAR int RTYPE = REALSXP;
static constexpr int RTYPE = REALSXP;
static inline double NA() { return NA_REAL; }
static inline RCPP_CONSTEXPR_FUNC double ZERO() { return 0.0; }
static inline RCPP_CONSTEXPR_FUNC double ONE() { return 1.0; }
static inline constexpr double ZERO() { return 0.0; }
static inline constexpr double ONE() { return 1.0; }
};

template<>
struct rtype_helper< int > {
typedef int type;
static RCPP_CONSTEXPR_VAR int RTYPE = INTSXP;
static constexpr int RTYPE = INTSXP;
static inline int NA() { return NA_INTEGER; }
static inline RCPP_CONSTEXPR_FUNC int ZERO() { return 0; }
static inline RCPP_CONSTEXPR_FUNC int ONE() { return 1; }
static inline constexpr int ZERO() { return 0; }
static inline constexpr int ONE() { return 1; }
};

template< typename T >
struct rtype {
typedef typename rtype_helper< typename ctype< T >::type >::type type;
typedef rtype_helper< typename ctype< T >::type > helper_type;
static RCPP_CONSTEXPR_VAR int RTYPE = helper_type::RTYPE;
static constexpr int RTYPE = helper_type::RTYPE;
static inline T NA() { return helper_type::NA(); }
static inline RCPP_CONSTEXPR_FUNC T ZERO() { return helper_type::ZERO(); }
static inline RCPP_CONSTEXPR_FUNC T ONE() { return helper_type::ONE(); }
static inline constexpr T ZERO() { return helper_type::ZERO(); }
static inline constexpr T ONE() { return helper_type::ONE(); }
};

struct log {
@@ -483,7 +459,4 @@ void sqrt(InputIterator begin, InputIterator end, OutputIterator out) {
} // namespace algorithm
} // namespace Rcpp

#undef RCPP_CONSTEXPR_FUNC
#undef RCPP_CONSTEXPR_VAR

#endif
36 changes: 24 additions & 12 deletions inst/include/Rcpp/exceptions.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@
// exceptions.h: Rcpp R/C++ interface class library -- exceptions
//
// Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2021 - 2020 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
// Copyright (C) 2021 - 2024 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois, Iñaki Ucar and James J Balamuta
//
// This file is part of Rcpp.
//
@@ -170,19 +171,30 @@ struct LongjumpException {
}
};

} // namespace Rcpp

#define RCPP_ADVANCED_EXCEPTION_CLASS(__CLASS__, __WHAT__) \
class __CLASS__ : public std::exception { \
public: \
__CLASS__( ) throw() : message( std::string(__WHAT__) + "." ){} \
__CLASS__( const std::string& message ) throw() : \
message( std::string(__WHAT__) + ": " + message + "."){} \
template <typename... Args> \
__CLASS__( const char* fmt, Args&&... args ) throw() : \
message( tfm::format(fmt, std::forward<Args>(args)... ) ){} \
virtual ~__CLASS__() throw(){} \
virtual const char* what() const throw() { return message.c_str(); } \
private: \
std::string message; \
};

// Determine whether to use variadic templated RCPP_ADVANCED_EXCEPTION_CLASS,
// warning, and stop exception functions or to use the generated argument macro
// based on whether the compiler supports c++11 or not.
#if __cplusplus >= 201103L
# include <Rcpp/exceptions/cpp11/exceptions.h>
#else
# include <Rcpp/exceptions/cpp98/exceptions.h>
#endif
template <typename... Args>
inline void warning(const char* fmt, Args&&... args ) {
Rf_warning("%s", tfm::format(fmt, std::forward<Args>(args)... ).c_str());
}

namespace Rcpp {
template <typename... Args>
inline void NORET stop(const char* fmt, Args&&... args) {
throw Rcpp::exception( tfm::format(fmt, std::forward<Args>(args)... ).c_str() );
}

#define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__) \
class __CLASS__ : public std::exception{ \
56 changes: 0 additions & 56 deletions inst/include/Rcpp/exceptions/cpp11/exceptions.h

This file was deleted.

Loading