From d8eac7ac5f7808d41a4da39dc506170e0b22e6cc Mon Sep 17 00:00:00 2001 From: qddyy Date: Wed, 18 Dec 2024 08:42:35 +0800 Subject: [PATCH] use `sizeof...` --- src/pmt_interface.cpp | 46 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/pmt_interface.cpp b/src/pmt_interface.cpp index 2097644..62a977d 100644 --- a/src/pmt_interface.cpp +++ b/src/pmt_interface.cpp @@ -5,12 +5,10 @@ using namespace Rcpp; #include "pmt/permutation.hpp" #include "pmt/progress.hpp" +#include #include -template -using tag_t = std::integral_constant; - -template +template constexpr auto Rf_lang = nullptr; template <> @@ -19,7 +17,7 @@ constexpr auto Rf_lang<2> = Rf_lang2; template <> constexpr auto Rf_lang<3> = Rf_lang3; -template +template class StatFunc : public Function { public: using Function::Function; @@ -27,22 +25,22 @@ class StatFunc : public Function { template auto operator()(Args&&... args) const { - return _invoke(tag_t(), std::forward(args)...); + return _invoke(std::integral_constant(), std::forward(args)...); } private: template - auto _invoke(tag_t<0>, Args&&... args) const + auto _invoke(std::false_type, Args&&... args) const { return [r_closure = Function(Function::operator()(std::forward(args)...))](auto&&... args) { return as(r_closure(std::forward(args)...)); }; } - template - auto _invoke(tag_t, Args&&... args) const + template + auto _invoke(std::true_type, Args&&... args) const { - return [r_call = RObject(Rf_lang(Function::operator()(std::forward(args)...), std::forward(args)...))](auto&&...) { + return [r_call = RObject(Rf_lang(Function::operator()(std::forward(args)...), std::forward(args)...))](auto&&...) { return as(Rcpp_fast_eval(r_call, R_GlobalEnv)); }; } @@ -59,8 +57,8 @@ SEXP twosample_pmt( const bool progress) { return progress ? - impl_twosample_pmt>(clone(x), clone(y), statistic_func, n_permu) : - impl_twosample_pmt>(clone(x), clone(y), statistic_func, n_permu); + impl_twosample_pmt>(clone(x), clone(y), statistic_func, n_permu) : + impl_twosample_pmt>(clone(x), clone(y), statistic_func, n_permu); } #include "pmt/impl_ksample_pmt.hpp" @@ -74,8 +72,8 @@ SEXP ksample_pmt( const bool progress) { return progress ? - impl_ksample_pmt>(data, clone(group), statistic_func, n_permu) : - impl_ksample_pmt>(data, clone(group), statistic_func, n_permu); + impl_ksample_pmt>(data, clone(group), statistic_func, n_permu) : + impl_ksample_pmt>(data, clone(group), statistic_func, n_permu); } #include "pmt/impl_multcomp_pmt.hpp" @@ -91,8 +89,8 @@ SEXP multcomp_pmt( const bool progress) { return progress ? - impl_multcomp_pmt>(group_i, group_j, data, clone(group), statistic_func, n_permu) : - impl_multcomp_pmt>(group_i, group_j, data, clone(group), statistic_func, n_permu); + impl_multcomp_pmt>(group_i, group_j, data, clone(group), statistic_func, n_permu) : + impl_multcomp_pmt>(group_i, group_j, data, clone(group), statistic_func, n_permu); } #include "pmt/impl_paired_pmt.hpp" @@ -106,8 +104,8 @@ SEXP paired_pmt( const bool progress) { return progress ? - impl_paired_pmt>(clone(x), clone(y), statistic_func, n_permu) : - impl_paired_pmt>(clone(x), clone(y), statistic_func, n_permu); + impl_paired_pmt>(clone(x), clone(y), statistic_func, n_permu) : + impl_paired_pmt>(clone(x), clone(y), statistic_func, n_permu); } #include "pmt/impl_rcbd_pmt.hpp" @@ -120,8 +118,8 @@ SEXP rcbd_pmt( const bool progress) { return progress ? - impl_rcbd_pmt>(clone(data), statistic_func, n_permu) : - impl_rcbd_pmt>(clone(data), statistic_func, n_permu); + impl_rcbd_pmt>(clone(data), statistic_func, n_permu) : + impl_rcbd_pmt>(clone(data), statistic_func, n_permu); } #include "pmt/impl_association_pmt.hpp" @@ -135,8 +133,8 @@ SEXP association_pmt( const bool progress) { return progress ? - impl_association_pmt>(clone(x), clone(y), statistic_func, n_permu) : - impl_association_pmt>(clone(x), clone(y), statistic_func, n_permu); + impl_association_pmt>(clone(x), clone(y), statistic_func, n_permu) : + impl_association_pmt>(clone(x), clone(y), statistic_func, n_permu); } #include "pmt/impl_table_pmt.hpp" @@ -150,6 +148,6 @@ SEXP table_pmt( const bool progress) { return progress ? - impl_table_pmt>(clone(row), clone(col), statistic_func, n_permu) : - impl_table_pmt>(clone(row), clone(col), statistic_func, n_permu); + impl_table_pmt>(clone(row), clone(col), statistic_func, n_permu) : + impl_table_pmt>(clone(row), clone(col), statistic_func, n_permu); } \ No newline at end of file