Skip to content

Commit eaa119a

Browse files
committed
define C++11 advanced exceptions unconditionally
1 parent 30edbf5 commit eaa119a

File tree

4 files changed

+31
-245
lines changed

4 files changed

+31
-245
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2025-03-24 Iñaki Ucar <[email protected]>
2+
3+
* inst/include/Rcpp/exceptions.h: Include C+11 variadic template definitions
4+
unconditionally
5+
* inst/include/Rcpp/exceptions/cpp11/exceptions.h: Removed
6+
* inst/include/Rcpp/exceptions/cpp98/exceptions.h: Idem
7+
18
2025-03-21 Dirk Eddelbuettel <[email protected]>
29

310
* DESCRIPTION (Version, Date): Roll micro version and date

inst/include/Rcpp/exceptions.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// exceptions.h: Rcpp R/C++ interface class library -- exceptions
33
//
44
// Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
5-
// Copyright (C) 2021 - 2020 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
5+
// Copyright (C) 2021 - 2024 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
6+
// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois, Iñaki Ucar and James J Balamuta
67
//
78
// This file is part of Rcpp.
89
//
@@ -170,19 +171,30 @@ struct LongjumpException {
170171
}
171172
};
172173

173-
} // namespace Rcpp
174-
174+
#define RCPP_ADVANCED_EXCEPTION_CLASS(__CLASS__, __WHAT__) \
175+
class __CLASS__ : public std::exception { \
176+
public: \
177+
__CLASS__( ) throw() : message( std::string(__WHAT__) + "." ){} \
178+
__CLASS__( const std::string& message ) throw() : \
179+
message( std::string(__WHAT__) + ": " + message + "."){} \
180+
template <typename... Args> \
181+
__CLASS__( const char* fmt, Args&&... args ) throw() : \
182+
message( tfm::format(fmt, std::forward<Args>(args)... ) ){} \
183+
virtual ~__CLASS__() throw(){} \
184+
virtual const char* what() const throw() { return message.c_str(); } \
185+
private: \
186+
std::string message; \
187+
};
175188

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

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

187199
#define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__) \
188200
class __CLASS__ : public std::exception{ \

inst/include/Rcpp/exceptions/cpp11/exceptions.h

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)