@@ -137,7 +137,7 @@ high-level \proglang{R} syntax in \proglang{C++}. Hence, with \sugar, the
137
137
\proglang{C++} version of ` foo ` now becomes:
138
138
139
139
``` cpp
140
- Rcpp::NumericVector foo (Rcpp::NumericVector x,
140
+ Rcpp::NumericVector foo (Rcpp::NumericVector x,
141
141
Rcpp::NumericVector y) {
142
142
return ifelse(x < y, x * x, -(y * y));
143
143
}
@@ -308,7 +308,7 @@ length. Each element of the result expression evaluates to `TRUE` if
308
308
the corresponding input is a missing value, or ` FALSE ` otherwise.
309
309
310
310
``` cpp
311
- IntegerVector x =
311
+ IntegerVector x =
312
312
IntegerVector::create (0, 1, NA_INTEGER, 3);
313
313
314
314
is_na(x)
@@ -322,7 +322,7 @@ Given a sugar expression of any type, `seq_along` creates an
322
322
integer sugar expression whose values go from 1 to the size of the input.
323
323
324
324
```cpp
325
- IntegerVector x =
325
+ IntegerVector x =
326
326
IntegerVector::create( 0, 1, NA_INTEGER, 3 );
327
327
328
328
IntegerVector y = seq_along(x);
@@ -337,7 +337,7 @@ second expression, since the abstract syntax tree is built at compile time.
337
337
338
338
### seq_len
339
339
340
- ` seq_len ` creates an integer sugar expression whose
340
+ ` seq_len ` creates an integer sugar expression whose
341
341
\ith\ element expands to ` i ` . ` seq_len ` is particularly useful in
342
342
conjunction with ` sapply ` and ` lapply ` .
343
343
@@ -411,7 +411,7 @@ called `result_type`
411
411
412
412
```cpp
413
413
template <typename T>
414
- struct square : std::unary_function<T, T > {
414
+ struct square : std::function<T(T) > {
415
415
T operator()(const T& x){
416
416
return x * x;
417
417
}
@@ -491,9 +491,9 @@ beta, binom, cauchy, chisq, exp, f, gamma, geom, hyper, lnorm, logis, nbeta,
491
491
nbinom, nbinom_mu, nchisq, nf, norm, nt, pois, t, unif, and weibull.
492
492
493
493
Note that the parameterization used in these sugar functions may differ between
494
- the top-level functions exposed in an \proglang{R} session. For example,
494
+ the top-level functions exposed in an \proglang{R} session. For example,
495
495
the internal \code{rexp} is parameterized by \code{scale},
496
- whereas the R-level \code{stats::rexp} is parameterized by \code{rate}.
496
+ whereas the R-level \code{stats::rexp} is parameterized by \code{rate}.
497
497
Consult \href{http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Distribution-functions}{Distribution Functions}
498
498
for more details on the parameterization used for these sugar functions.
499
499
@@ -568,13 +568,13 @@ is given here:
568
568
template <int RTYPE, bool na, typename VECTOR>
569
569
class VectorBase {
570
570
public:
571
- struct r_type :
571
+ struct r_type :
572
572
traits::integral_constant<int,RTYPE>{};
573
573
struct can_have_na :
574
574
traits::integral_constant<bool,na>{};
575
-
576
- typedef typename
577
- traits::storage_type<RTYPE>::type
575
+
576
+ typedef typename
577
+ traits::storage_type<RTYPE>::type
578
578
stored_type;
579
579
580
580
VECTOR& get_ref(){
@@ -586,18 +586,18 @@ public:
586
586
this)->operator[](i);
587
587
}
588
588
589
- inline int size() const {
589
+ inline int size() const {
590
590
return static_cast<const VECTOR*>(
591
- this)->size();
591
+ this)->size();
592
592
}
593
593
594
594
/* definition ommited here */
595
595
class iterator;
596
596
597
- inline iterator begin() const {
598
- return iterator(*this, 0);
597
+ inline iterator begin() const {
598
+ return iterator(*this, 0);
599
599
}
600
- inline iterator end() const {
600
+ inline iterator end() const {
601
601
return iterator(*this, size());
602
602
}
603
603
}
@@ -633,27 +633,27 @@ the template class `Rcpp::sugar::Sapply` is given below:
633
633
template <int RTYPE, bool NA,
634
634
typename T, typename Function>
635
635
class Sapply : public VectorBase <
636
- Rcpp::traits::r_sexptype_traits< typename
636
+ Rcpp::traits::r_sexptype_traits< typename
637
637
::Rcpp::traits::result_of<Function>::type
638
638
>::rtype,
639
639
true,
640
640
Sapply<RTYPE, NA, T, Function>
641
641
> {
642
642
public:
643
- typedef typename
643
+ typedef typename
644
644
::Rcpp::traits::result_of<Function >::type;
645
-
645
+
646
646
const static int RESULT_R_TYPE =
647
647
Rcpp::traits::r_sexptype_traits<
648
648
result_type>::rtype;
649
-
649
+
650
650
typedef Rcpp::VectorBase<RTYPE,NA,T> VEC;
651
-
652
- typedef typename
651
+
652
+ typedef typename
653
653
Rcpp::traits::r_vector_element_converter<
654
654
RESULT_R_TYPE>::type
655
655
converter_type;
656
-
656
+
657
657
typedef typename Rcpp::traits::storage_type<
658
658
RESULT_R_TYPE>::type STORAGE;
659
659
@@ -663,9 +663,9 @@ public:
663
663
inline STORAGE operator []( int i ) const {
664
664
return converter_type::get(fun(vec[i]));
665
665
}
666
-
667
- inline int size() const {
668
- return vec.size();
666
+
667
+ inline int size() const {
668
+ return vec.size();
669
669
}
670
670
671
671
private:
@@ -675,13 +675,13 @@ private:
675
675
676
676
// sugar
677
677
678
- template <int RTYPE, bool _NA_,
678
+ template <int RTYPE, bool _NA_,
679
679
typename T, typename Function >
680
680
inline sugar::Sapply<RTYPE, _NA_, T, Function>
681
681
sapply (const Rcpp::VectorBase<RTYPE,_ NA_ ,T>& t,
682
682
Function fun) {
683
-
684
- return
683
+
684
+ return
685
685
sugar::Sapply<RTYPE,_NA_,T,Function>(t, fun);
686
686
}
687
687
```
@@ -703,8 +703,8 @@ template class queries the template argument via the `Rcpp::traits::result_of`
703
703
template.
704
704
705
705
```cpp
706
- typedef typename
707
- ::Rcpp::traits::result_of<Function>::type
706
+ typedef typename
707
+ ::Rcpp::traits::result_of<Function>::type
708
708
result_type;
709
709
```
710
710
@@ -717,7 +717,7 @@ struct result_of{
717
717
typedef typename T::result_type type;
718
718
};
719
719
720
- template <typename RESULT_TYPE,
720
+ template <typename RESULT_TYPE,
721
721
typename INPUT_TYPE>
722
722
struct result_of<RESULT_TYPE (*)(INPUT_TYPE)> {
723
723
typedef RESULT_TYPE type;
@@ -762,7 +762,7 @@ of a `REALSXP` expression is `double`.
762
762
763
763
``` cpp
764
764
typedef typename
765
- Rcpp::traits::storage_type<RESULT_R_TYPE>::type
765
+ Rcpp::traits::storage_type<RESULT_R_TYPE>::type
766
766
STORAGE;
767
767
```
768
768
@@ -785,7 +785,7 @@ template <int RTYPE, bool NA,
785
785
typename T, typename Function>
786
786
class Sapply : public VectorBase <
787
787
Rcpp::traits::r_sexptype_traits<
788
- typename
788
+ typename
789
789
::Rcpp::traits::result_of<Function>::type
790
790
>::rtype,
791
791
true,
@@ -799,13 +799,13 @@ is the manifestation of the _CRTP_.
799
799
800
800
### Constructor
801
801
802
-
802
+
803
803
The constructor of the `Sapply` class template is straightforward, it
804
804
simply consists of holding the reference to the input expression and the
805
805
function.
806
806
807
807
```cpp
808
- Sapply(const VEC& vec_, Function fun_):
808
+ Sapply(const VEC& vec_, Function fun_):
809
809
vec(vec_), fun(fun_){}
810
810
811
811
private:
@@ -825,8 +825,8 @@ and the converter. Both these methods are inline to maximize performance:
825
825
inline STORAGE operator [](int i) const {
826
826
return converter_type::get(fun(vec[i]));
827
827
}
828
- inline int size () const {
829
- return vec.size();
828
+ inline int size () const {
829
+ return vec.size();
830
830
}
831
831
```
832
832
0 commit comments