Skip to content

Commit d914443

Browse files
committed
Merge pull request #206 from romainfrancois/master
Better Rcpp::stop
2 parents ee78ef9 + e490d34 commit d914443

File tree

7 files changed

+1091
-1
lines changed

7 files changed

+1091
-1
lines changed

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
\item The \code{[dpq]nbinom_mu()} scalar functions are now available via
1212
the \code{R::} namespace when R 3.1.2 or newer is used.
1313
\item Add an additional test for AIX before attempting to include \code{execinfo.h}.
14+
\item Rcpp::stop gains a printf like syntax, inspired from the implementation in
15+
Rcpp11, using tinyformat
1416
}
1517
\item Changes in Rcpp Attributes:
1618
\itemize{

inst/include/Rcpp/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#define Rcpp_Version(v,p,s) (((v) * 65536) + ((p) * 256) + (s))
2626

27-
#define RCPP_VERSION Rcpp_Version(0,11,3)
27+
#define RCPP_VERSION Rcpp_Version(0,11,4)
2828

2929
#endif
3030

inst/include/Rcpp/exceptions.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,56 @@ namespace Rcpp{
195195
inline void stop(const std::string& message) {
196196
throw Rcpp::exception(message.c_str());
197197
}
198+
199+
template <typename T1>
200+
inline void stop(const char* fmt, const T1& arg1) {
201+
throw Rcpp::exception( tfm::format(fmt, arg1 ).c_str() );
202+
}
203+
204+
template <typename T1, typename T2>
205+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2) {
206+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2 ).c_str() );
207+
}
208+
209+
template <typename T1, typename T2, typename T3>
210+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3) {
211+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3).c_str() );
212+
}
213+
214+
template <typename T1, typename T2, typename T3, typename T4>
215+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
216+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4).c_str() );
217+
}
218+
219+
template <typename T1, typename T2, typename T3, typename T4, typename T5>
220+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5) {
221+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5).c_str() );
222+
}
223+
224+
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
225+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6) {
226+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6).c_str() );
227+
}
228+
229+
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
230+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7) {
231+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7).c_str() );
232+
}
233+
234+
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
235+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8) {
236+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).c_str() );
237+
}
238+
239+
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
240+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9) {
241+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).c_str() );
242+
}
243+
244+
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
245+
inline void stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9, const T10& arg10) {
246+
throw Rcpp::exception( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10).c_str() );
247+
}
198248
}
199249

200250
inline void forward_exception_to_r( const std::exception& ex){

0 commit comments

Comments
 (0)