@@ -8,45 +8,6 @@ namespace Rcpp {
88namespace algorithm {
99
1010namespace helpers {
11- template < typename T >
12- struct rtype_helper {
13- /*
14- typedef T type;
15- static RCPP_CONSTEXPR int RTYPE = REALSXP;
16- static inline double NA() { return NA_REAL; }
17- static inline RCPP_CONSTEXPR double ZERO() { return 0.0; }
18- static inline RCPP_CONSTEXPR double ONE() { return 1.0; }
19- */
20- };
21-
22- template <>
23- struct rtype_helper < double > {
24- typedef double type;
25- static RCPP_CONSTEXPR int RTYPE = REALSXP;
26- static inline double NA () { return NA_REAL; }
27- static inline RCPP_CONSTEXPR double ZERO () { return 0.0 ; }
28- static inline RCPP_CONSTEXPR double ONE () { return 1.0 ; }
29- };
30-
31- template <>
32- struct rtype_helper < int > {
33- typedef int type;
34- static RCPP_CONSTEXPR int RTYPE = INTSXP;
35- static inline int NA () { return NA_INTEGER; }
36- static inline RCPP_CONSTEXPR int ZERO () { return 0 ; }
37- static inline RCPP_CONSTEXPR int ONE () { return 1 ; }
38- };
39-
40- template < typename T >
41- struct rtype {
42- typedef typename rtype_helper< typename traits::remove_const_and_reference< T >::type >::type type;
43- static RCPP_CONSTEXPR int RTYPE =
44- rtype_helper< typename traits::remove_const_and_reference< T >::type >::RTYPE;
45- static inline T NA () { return rtype_helper< typename traits::remove_const_and_reference< T >::type >::NA (); }
46- static inline RCPP_CONSTEXPR T ZERO () { return rtype_helper< typename traits::remove_const_and_reference< T >::type >::ZERO (); }
47- static inline RCPP_CONSTEXPR T ONE () { return rtype_helper< typename traits::remove_const_and_reference< T >::type >::ONE (); }
48- };
49-
5011 typedef struct {char a[1 ];} CTYPE_CHAR;
5112 typedef struct {char a[2 ];} CTYPE_SHORT;
5213 typedef struct {char a[3 ];} CTYPE_INT;
@@ -157,6 +118,45 @@ namespace helpers {
157118 static const bool value = ctype_helper< sizeof (test(make())) >::value;
158119 };
159120
121+ template < typename T >
122+ struct rtype_helper {
123+ /*
124+ typedef T type;
125+ static RCPP_CONSTEXPR int RTYPE = REALSXP;
126+ static inline double NA() { return NA_REAL; }
127+ static inline RCPP_CONSTEXPR double ZERO() { return 0.0; }
128+ static inline RCPP_CONSTEXPR double ONE() { return 1.0; }
129+ */
130+ };
131+
132+ template <>
133+ struct rtype_helper < double > {
134+ typedef double type;
135+ static RCPP_CONSTEXPR int RTYPE = REALSXP;
136+ static inline double NA () { return NA_REAL; }
137+ static inline RCPP_CONSTEXPR double ZERO () { return 0.0 ; }
138+ static inline RCPP_CONSTEXPR double ONE () { return 1.0 ; }
139+ };
140+
141+ template <>
142+ struct rtype_helper < int > {
143+ typedef int type;
144+ static RCPP_CONSTEXPR int RTYPE = INTSXP;
145+ static inline int NA () { return NA_INTEGER; }
146+ static inline RCPP_CONSTEXPR int ZERO () { return 0 ; }
147+ static inline RCPP_CONSTEXPR int ONE () { return 1 ; }
148+ };
149+
150+ template < typename T >
151+ struct rtype {
152+ typedef typename rtype_helper< typename ctype< T >::type >::type type;
153+ typedef rtype_helper< typename ctype< T >::type > helper_type;
154+ static RCPP_CONSTEXPR int RTYPE = helper_type::RTYPE;
155+ static inline T NA () { return helper_type::NA (); }
156+ static inline RCPP_CONSTEXPR T ZERO () { return helper_type::ZERO (); }
157+ static inline RCPP_CONSTEXPR T ONE () { return helper_type::ONE (); }
158+ };
159+
160160 struct log {
161161 template < typename T >
162162 inline double operator ()(T val) {
0 commit comments