forked from jonclayden/RcppArray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (44 loc) · 1.28 KB
/
main.cpp
File metadata and controls
54 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "RcppArray.h"
#include <Rcpp/Lightest>
using namespace Rcpp;
template <typename T, size_t D> void printArray (const std::array<T,D> &arr) {
Rcout << "Array: ";
for (size_t i=0; i<D; i++)
Rcout << arr[i] << " ";
Rcout << std::endl;
}
// [[Rcpp::export]]
void intArray(RObject x) {
std::array<int,3> a = Rcpp::as<std::array<int,3>>(x);
printArray(a);
}
// [[Rcpp::export]]
void unsignedArray(RObject x) {
std::array<unsigned int,3> a = Rcpp::as<std::array<unsigned int,3>>(x);
printArray(a);
}
// [[Rcpp::export]]
void doubleArray(RObject x) {
std::array<double,3> a = Rcpp::as<std::array<double,3>>(x);
printArray(a);
}
// [[Rcpp::export]]
void stringArray(RObject x) {
std::array<std::string,3> a = Rcpp::as<std::array<std::string,3>>(x);
printArray(a);
}
// [[Rcpp::export]]
void int64Array(RObject x) {
std::array<int64_t,3> a = Rcpp::as<std::array<int64_t,3>>(x);
printArray(a);
}
// [[Rcpp::export]]
void intDoubleString(RObject x) {
std::tuple<int,double,std::string> t = Rcpp::as<std::tuple<int,double,std::string>>(x);
Rcout << "Tuple: " << std::get<0>(t) << " " << std::get<1>(t) << " " << std::get<2>(t) << std::endl;
}
// [[Rcpp::export]]
SEXP wrapTuple() {
std::tuple<int,double,std::string> t = { 1, 2.56, "test" };
return Rcpp::wrap(t);
}