|
22 | 22 | #ifndef Rcpp__sugar__sapply_h |
23 | 23 | #define Rcpp__sugar__sapply_h |
24 | 24 |
|
| 25 | +#if (__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 26 | + #define RCPP_USE_CXX11 1 |
| 27 | +#else |
| 28 | + #define RCPP_USE_CXX11 0 |
| 29 | +#endif |
| 30 | + |
| 31 | +#if RCPP_USE_CXX11 |
| 32 | + #include <type_traits> |
| 33 | +#endif |
| 34 | + |
25 | 35 | namespace Rcpp{ |
26 | 36 | namespace sugar{ |
27 | 37 |
|
| 38 | +template <typename Function, typename SugarExpression> |
| 39 | +struct sapply_application_result_of |
| 40 | +{ |
| 41 | +#if RCPP_USE_CXX11 |
| 42 | + typedef typename ::std::result_of<Function(typename SugarExpression::stored_type)>::type type; |
| 43 | +#else |
| 44 | + typedef typename ::Rcpp::traits::result_of<Function>::type type; |
| 45 | +#endif |
| 46 | +} ; |
| 47 | + |
| 48 | +// template <typename Function, typename SugarExpression> |
| 49 | +// using sapply_application_result_of_t = typename sapply_application_result_of<Function, SugarExpression>::type; |
| 50 | + |
28 | 51 | template <int RTYPE, bool NA, typename T, typename Function, bool NO_CONVERSION> |
29 | 52 | class Sapply : public VectorBase< |
30 | 53 | Rcpp::traits::r_sexptype_traits< |
31 | | - typename ::Rcpp::traits::result_of<Function>::type |
| 54 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type |
32 | 55 | >::rtype , |
33 | 56 | true , |
34 | 57 | Sapply<RTYPE,NA,T,Function,NO_CONVERSION> |
35 | 58 | > { |
36 | 59 | public: |
37 | | - typedef typename ::Rcpp::traits::result_of<Function>::type result_type ; |
| 60 | + typedef typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type result_type ; |
38 | 61 | const static int RESULT_R_TYPE = |
39 | 62 | Rcpp::traits::r_sexptype_traits<result_type>::rtype ; |
40 | 63 |
|
@@ -65,13 +88,13 @@ class Sapply : public VectorBase< |
65 | 88 | template <int RTYPE, bool NA, typename T, typename Function> |
66 | 89 | class Sapply<RTYPE,NA,T,Function,true> : public VectorBase< |
67 | 90 | Rcpp::traits::r_sexptype_traits< |
68 | | - typename ::Rcpp::traits::result_of<Function>::type |
| 91 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type |
69 | 92 | >::rtype , |
70 | 93 | true , |
71 | 94 | Sapply<RTYPE,NA,T,Function,true> |
72 | 95 | > { |
73 | 96 | public: |
74 | | - typedef typename ::Rcpp::traits::result_of<Function>::type result_type ; |
| 97 | + typedef typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type result_type ; |
75 | 98 | const static int RESULT_R_TYPE = |
76 | 99 | Rcpp::traits::r_sexptype_traits<result_type>::rtype ; |
77 | 100 |
|
@@ -102,15 +125,15 @@ template <int RTYPE, bool NA, typename T, typename Function > |
102 | 125 | inline sugar::Sapply< |
103 | 126 | RTYPE,NA,T,Function, |
104 | 127 | 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 |
| 128 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type , |
| 129 | + typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type >::rtype >::type |
107 | 130 | >::value |
108 | 131 | > |
109 | 132 | sapply( const Rcpp::VectorBase<RTYPE,NA,T>& t, Function fun ){ |
110 | 133 | return sugar::Sapply<RTYPE,NA,T,Function, |
111 | 134 | 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 |
| 135 | + typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type , |
| 136 | + typename Rcpp::traits::storage_type< traits::r_sexptype_traits< typename ::Rcpp::sugar::sapply_application_result_of<Function, T>::type >::rtype >::type |
114 | 137 | >::value >( t, fun ) ; |
115 | 138 | } |
116 | 139 |
|
|
0 commit comments