|
22 | 22 | #ifndef Rcpp__sugar__sapply_h |
23 | 23 | #define Rcpp__sugar__sapply_h |
24 | 24 |
|
| 25 | +#if defined(RCPP_USING_CXX0X_OR_LATER) |
| 26 | + #include <type_traits> // ::std::result_of |
| 27 | +#endif |
| 28 | + |
25 | 29 | namespace Rcpp{ |
26 | 30 | namespace sugar{ |
27 | 31 |
|
| 32 | +template <typename Function, typename SugarExpression> |
| 33 | +struct sapply_application_result_of |
| 34 | +{ |
| 35 | +#if defined(RCPP_USING_CXX0X_OR_LATER) |
| 36 | + typedef typename ::std::result_of<Function(typename SugarExpression::stored_type)>::type type; |
| 37 | +#else |
| 38 | + typedef typename ::Rcpp::traits::result_of<Function>::type type; |
| 39 | +#endif |
| 40 | +} ; |
| 41 | + |
| 42 | +// template <typename Function, typename SugarExpression> |
| 43 | +// using sapply_application_result_of_t = typename sapply_application_result_of<Function, SugarExpression>::type; |
| 44 | + |
28 | 45 | template <int RTYPE, bool NA, typename T, typename Function, bool NO_CONVERSION> |
29 | 46 | class Sapply : public VectorBase< |
30 | 47 | Rcpp::traits::r_sexptype_traits< |
31 | | - typename ::Rcpp::traits::result_of<Function>::type |
| 48 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type |
32 | 49 | >::rtype , |
33 | 50 | true , |
34 | 51 | Sapply<RTYPE,NA,T,Function,NO_CONVERSION> |
35 | 52 | > { |
36 | 53 | public: |
37 | | - typedef typename ::Rcpp::traits::result_of<Function>::type result_type ; |
| 54 | + typedef typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type result_type ; |
38 | 55 | const static int RESULT_R_TYPE = |
39 | 56 | Rcpp::traits::r_sexptype_traits<result_type>::rtype ; |
40 | 57 |
|
@@ -65,13 +82,13 @@ class Sapply : public VectorBase< |
65 | 82 | template <int RTYPE, bool NA, typename T, typename Function> |
66 | 83 | class Sapply<RTYPE,NA,T,Function,true> : public VectorBase< |
67 | 84 | Rcpp::traits::r_sexptype_traits< |
68 | | - typename ::Rcpp::traits::result_of<Function>::type |
| 85 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type |
69 | 86 | >::rtype , |
70 | 87 | true , |
71 | 88 | Sapply<RTYPE,NA,T,Function,true> |
72 | 89 | > { |
73 | 90 | public: |
74 | | - typedef typename ::Rcpp::traits::result_of<Function>::type result_type ; |
| 91 | + typedef typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type result_type ; |
75 | 92 | const static int RESULT_R_TYPE = |
76 | 93 | Rcpp::traits::r_sexptype_traits<result_type>::rtype ; |
77 | 94 |
|
@@ -102,15 +119,15 @@ template <int RTYPE, bool NA, typename T, typename Function > |
102 | 119 | inline sugar::Sapply< |
103 | 120 | RTYPE,NA,T,Function, |
104 | 121 | traits::same_type< |
105 | | - typename ::Rcpp::traits::result_of<Function>::type , |
106 | | - typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::traits::result_of<Function>::type >::rtype >::type |
| 122 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type , |
| 123 | + typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type >::rtype >::type |
107 | 124 | >::value |
108 | 125 | > |
109 | 126 | sapply( const Rcpp::VectorBase<RTYPE,NA,T>& t, Function fun ){ |
110 | 127 | return sugar::Sapply<RTYPE,NA,T,Function, |
111 | 128 | traits::same_type< |
112 | | - typename ::Rcpp::traits::result_of<Function>::type , |
113 | | - typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::traits::result_of<Function>::type >::rtype >::type |
| 129 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type , |
| 130 | + typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type >::rtype >::type |
114 | 131 | >::value >( t, fun ) ; |
115 | 132 | } |
116 | 133 |
|
|
0 commit comments