Skip to content

Commit 11b9f12

Browse files
Better Rcpp::stop. See tidyverse/dplyr#794 for the full story
1 parent 5d7cfc4 commit 11b9f12

File tree

3 files changed

+1076
-0
lines changed

3 files changed

+1076
-0
lines changed

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)