Skip to content

Commit c91eb89

Browse files
authored
Variadic templates refinement (#1336)
* add tests to check that void functions return invisibly * uncomment HAS_VARIADIC_TEMPLATES capability, simplify ifdefs * add missing is_void method to CppFunctionN * update ChangeLog
1 parent 982f784 commit c91eb89

File tree

17 files changed

+70
-24
lines changed

17 files changed

+70
-24
lines changed

ChangeLog

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2024-10-07 Iñaki Ucar <[email protected]>
2+
3+
* inst/include/Rcpp/platform/compiler.h: Uncomment HAS_VARIADIC_TEMPLATES
4+
macro definition
5+
* src/api.cpp: Simplify checks for variadic templates
6+
* inst/include/Rcpp/DataFrame.h: Idem
7+
* inst/include/Rcpp/DottedPair.h: Idem
8+
* inst/include/Rcpp/Function.h: Idem
9+
* inst/include/Rcpp/InternalFunctionWithStdFunction.h: Idem
10+
* inst/include/Rcpp/Language.h: Idem
11+
* inst/include/Rcpp/Pairlist.h: Idem
12+
* inst/include/Rcpp/grow.h: Idem
13+
* inst/include/Rcpp/internal/call.h: Idem
14+
* inst/include/Rcpp/module/class.h: Idem
15+
* inst/include/Rcpp/traits/index_sequence.h: Idem
16+
* inst/include/Rcpp/traits/named_object.h: Idem
17+
* inst/include/Rcpp/vector/Vector.h: Idem
18+
* inst/include/Rcpp/Module.h: Idem + add missing is_void method
19+
* inst/tinytest/test_module.R: Add test for void functions and methods
20+
121
2024-10-04 Dirk Eddelbuettel <[email protected]>
222

323
* DESCRIPTION (Version, Date): Roll micro version to 1.0.13.3

inst/include/Rcpp/DataFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ namespace Rcpp{
117117
static DataFrame_Impl create(){
118118
return DataFrame_Impl() ;
119119
}
120-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
120+
#if defined(HAS_VARIADIC_TEMPLATES)
121121
template <typename... T>
122122
static DataFrame_Impl create(const T&... args) {
123123
return DataFrame_Impl::from_list(Parent::create(args...));

inst/include/Rcpp/DottedPair.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ RCPP_API_CLASS(DottedPair_Impl),
3535
DottedPair_Impl(SEXP x) {
3636
Storage::set__(x) ;
3737
}
38-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
38+
#if defined(HAS_VARIADIC_TEMPLATES)
3939
template <typename... T>
4040
DottedPair_Impl(const T&... args) {
4141
Storage::set__(pairlist(args...));

inst/include/Rcpp/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace Rcpp{
8282
return Rcpp_fast_eval(call, R_GlobalEnv);
8383
}
8484

85-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
85+
#if defined(HAS_VARIADIC_TEMPLATES)
8686
template <typename... T>
8787
SEXP operator()(const T&... args) const {
8888
return invoke(pairlist(args...), R_GlobalEnv);

inst/include/Rcpp/InternalFunctionWithStdFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef Rcpp_InternalFunctionWithStdFunction_h
2424
#define Rcpp_InternalFunctionWithStdFunction_h
2525

26-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
26+
#if defined(HAS_VARIADIC_TEMPLATES)
2727
#include <Rcpp/internal/call.h>
2828
#endif
2929
#include <functional>

inst/include/Rcpp/Language.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace Rcpp{
102102
* 0.0 is wrapped as a numeric vector using wrap( const& double )
103103
* ...
104104
*/
105-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
105+
#if defined(HAS_VARIADIC_TEMPLATES)
106106
template <typename... T>
107107
Language_Impl(const std::string& symbol, const T&... t) {
108108
Storage::set__(pairlist(Rf_install(symbol.c_str()), t...) );

inst/include/Rcpp/Module.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace Rcpp{
8686
#include <Rcpp/module/CppFunction.h>
8787
#include <Rcpp/module/get_return_type.h>
8888

89-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
89+
#if defined(HAS_VARIADIC_TEMPLATES)
9090
namespace Rcpp {
9191
template <typename RESULT_TYPE, typename... T>
9292
inline void signature(std::string& s, const char* name) {
@@ -112,6 +112,7 @@ namespace Rcpp {
112112
}
113113

114114
inline int nargs() { return sizeof...(T); }
115+
inline bool is_void() { return std::is_void<RESULT_TYPE>::value; }
115116
inline void signature(std::string& s, const char* name) { Rcpp::signature<RESULT_TYPE, T...>(s, name); }
116117
inline DL_FUNC get_function_ptr() { return (DL_FUNC)ptr_fun; }
117118

@@ -176,7 +177,7 @@ namespace Rcpp{
176177
private:
177178
ParentMethod* parent_method_pointer ;
178179
} ;
179-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
180+
#if defined(HAS_VARIADIC_TEMPLATES)
180181
template <typename... T>
181182
inline void ctor_signature(std::string& s, const std::string& classname) {
182183
s.assign(classname);
@@ -380,7 +381,7 @@ namespace Rcpp{
380381

381382
} ;
382383

383-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
384+
#if defined(HAS_VARIADIC_TEMPLATES)
384385
template <bool IsConst,typename Class, typename RESULT_TYPE, typename... T>
385386
class CppMethodImplN : public CppMethod<Class> {
386387
public:
@@ -428,7 +429,7 @@ namespace Rcpp{
428429
return call<decltype(f), CLEANED_RESULT_TYPE, T...>(f, args);
429430
}
430431
inline int nargs() { return sizeof...(T); }
431-
inline bool is_void() { return std::is_void<RESULT_TYPE>::value;}
432+
inline bool is_void() { return std::is_void<RESULT_TYPE>::value; }
432433
inline bool is_const() { return IsConst; }
433434
inline void signature(std::string& s, const char* name) { Rcpp::signature<RESULT_TYPE,T...>(s, name); }
434435
private:
@@ -551,7 +552,7 @@ namespace Rcpp{
551552
} ;
552553
}
553554

554-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
555+
#if defined(HAS_VARIADIC_TEMPLATES)
555556
namespace Rcpp {
556557
template <typename RESULT_TYPE, typename... T>
557558
void function(const char* name_, RESULT_TYPE (*fun)(T... t), const char* docstring = 0) {

inst/include/Rcpp/Pairlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace Rcpp{
4242
Pairlist_Impl(SEXP x){
4343
Storage::set__(r_cast<LISTSXP>(x)) ;
4444
}
45-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
45+
#if defined(HAS_VARIADIC_TEMPLATES)
4646
template <typename... T>
4747
Pairlist_Impl(const T&... args ){
4848
Storage::set__(pairlist(args... )) ;

inst/include/Rcpp/grow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace Rcpp {
7070
return grow(Rf_mkString(head), y);
7171
}
7272

73-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
73+
#if defined(HAS_VARIADIC_TEMPLATES)
7474
template <typename T1>
7575
SEXP pairlist(const T1& t1) {
7676
return grow( t1, R_NilValue ) ;

inst/include/Rcpp/internal/call.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <Rcpp/traits/index_sequence.h>
55
#include <functional>
66

7-
#if defined(HAS_VARIADIC_TEMPLATES) || defined(RCPP_USING_CXX11)
7+
#if defined(HAS_VARIADIC_TEMPLATES)
88

99
namespace Rcpp {
1010
namespace internal {
@@ -15,7 +15,7 @@ template <typename... T> struct type_pack {};
1515
/**
1616
* This specialisation is for functions that return a value, whereas the below
1717
* is for void-returning functions.
18-
*
18+
*
1919
* The "* = nullptr" default argument allows both templates to be well-defined
2020
* regardless of which one is used.
2121
*/
@@ -40,7 +40,7 @@ SEXP call_impl(const F& fun, SEXP* args, type_pack<RESULT_TYPE, Us...>,
4040
* Helper for calling a function with an array of SEXP arguments,
4141
* where each argument is converted to the appropriate type before being passed
4242
* to the function. A compile-time sequence is used to index the SEXP array.
43-
*
43+
*
4444
* The function only needs the intended types of the result and arguments,
4545
* which allows the template to be used for function pointers, lambdas, and
4646
* `std::function` objects.

0 commit comments

Comments
 (0)