|
1 | 1 |
|
2 | 2 | // sapply.h: Rcpp R/C++ interface class library -- sapply |
3 | 3 | // |
4 | | -// Copyright (C) 2010 - 2023 Dirk Eddelbuettel and Romain Francois |
| 4 | +// Copyright (C) 2010 - 2024 Dirk Eddelbuettel and Romain Francois |
| 5 | +// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar |
5 | 6 | // |
6 | 7 | // This file is part of Rcpp. |
7 | 8 | // |
|
21 | 22 | #ifndef Rcpp__sugar__sapply_h |
22 | 23 | #define Rcpp__sugar__sapply_h |
23 | 24 |
|
24 | | -// This used to be conditional on a define and test in compiler.h |
25 | | -#include <type_traits> // ::std::result_of |
26 | | - |
27 | 25 | namespace Rcpp{ |
28 | 26 | namespace sugar{ |
29 | 27 |
|
30 | | -template <typename Function, typename SugarExpression> |
31 | | -struct sapply_application_result_of |
32 | | -{ |
33 | | -#if __cplusplus >= 201103L |
34 | | - #if __cplusplus < 201703L |
35 | | - // deprecated by C++17, removed by C++2020, see https://en.cppreference.com/w/cpp/types/result_of |
36 | | - typedef typename ::std::result_of<Function(typename SugarExpression::stored_type)>::type type; |
37 | | - #else |
38 | | - // since C++17, see https://en.cppreference.com/w/cpp/types/result_of |
39 | | - typedef typename ::std::invoke_result<Function, typename SugarExpression::stored_type>::type type; |
40 | | - #endif |
41 | | -#else |
42 | | - // TODO this else branch can likely go |
43 | | - typedef typename ::Rcpp::traits::result_of<Function>::type type; |
44 | | -#endif |
45 | | -}; |
46 | | - |
47 | | -// template <typename Function, typename SugarExpression> |
48 | | -// using sapply_application_result_of_t = typename sapply_application_result_of<Function, SugarExpression>::type; |
49 | | - |
50 | 28 | template <int RTYPE, bool NA, typename T, typename Function, bool NO_CONVERSION> |
51 | 29 | class Sapply : public VectorBase< |
52 | 30 | Rcpp::traits::r_sexptype_traits< |
53 | | - typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type |
| 31 | + typename ::Rcpp::traits::result_of<Function, T>::type |
54 | 32 | >::rtype , |
55 | 33 | true , |
56 | 34 | Sapply<RTYPE,NA,T,Function,NO_CONVERSION> |
57 | 35 | > { |
58 | 36 | public: |
59 | | - typedef typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type result_type ; |
| 37 | + typedef typename ::Rcpp::traits::result_of<Function, T>::type result_type ; |
60 | 38 | const static int RESULT_R_TYPE = |
61 | 39 | Rcpp::traits::r_sexptype_traits<result_type>::rtype ; |
62 | 40 |
|
@@ -87,13 +65,13 @@ class Sapply : public VectorBase< |
87 | 65 | template <int RTYPE, bool NA, typename T, typename Function> |
88 | 66 | class Sapply<RTYPE,NA,T,Function,true> : public VectorBase< |
89 | 67 | Rcpp::traits::r_sexptype_traits< |
90 | | - typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type |
| 68 | + typename ::Rcpp::traits::result_of<Function, T>::type |
91 | 69 | >::rtype , |
92 | 70 | true , |
93 | 71 | Sapply<RTYPE,NA,T,Function,true> |
94 | 72 | > { |
95 | 73 | public: |
96 | | - typedef typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type result_type ; |
| 74 | + typedef typename ::Rcpp::traits::result_of<Function, T>::type result_type ; |
97 | 75 | const static int RESULT_R_TYPE = |
98 | 76 | Rcpp::traits::r_sexptype_traits<result_type>::rtype ; |
99 | 77 |
|
@@ -124,15 +102,15 @@ template <int RTYPE, bool NA, typename T, typename Function > |
124 | 102 | inline sugar::Sapply< |
125 | 103 | RTYPE,NA,T,Function, |
126 | 104 | traits::same_type< |
127 | | - typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type , |
128 | | - typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type >::rtype >::type |
| 105 | + typename ::Rcpp::traits::result_of<Function, T>::type , |
| 106 | + typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::traits::result_of<Function, T>::type >::rtype >::type |
129 | 107 | >::value |
130 | 108 | > |
131 | 109 | sapply( const Rcpp::VectorBase<RTYPE,NA,T>& t, Function fun ){ |
132 | 110 | return sugar::Sapply<RTYPE,NA,T,Function, |
133 | 111 | traits::same_type< |
134 | | - typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type , |
135 | | - typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type >::rtype >::type |
| 112 | + typename ::Rcpp::traits::result_of<Function, T>::type , |
| 113 | + typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::traits::result_of<Function, T>::type >::rtype >::type |
136 | 114 | >::value >( t, fun ) ; |
137 | 115 | } |
138 | 116 |
|
|
0 commit comments