-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSimpleVector.h
More file actions
73 lines (57 loc) · 2.14 KB
/
SimpleVector.h
File metadata and controls
73 lines (57 loc) · 2.14 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef Rcpp__vector__impl_SimpleVector_h
#define Rcpp__vector__impl_SimpleVector_h
namespace Rcpp{
#undef VEC
#define VEC Vector<RTYPE,Storage>
template <int RTYPE, typename Storage>
class Vector :
public VectorOfRTYPE<RTYPE>,
public SugarVectorExpression<typename traits::storage_type<RTYPE>::type, VEC>
{
public:
typedef typename traits::storage_type<RTYPE>::type value_type ;
typedef value_type& reference ;
typedef const value_type& const_reference ;
typedef reference Proxy ;
typedef const_reference const_Proxy ;
typedef value_type* iterator ;
typedef const value_type* const_iterator ;
#include <Rcpp/vector/impl/RCPP_VECTOR_API.h>
public:
Vector( R_xlen_t n, value_type x ) {
reset(n);
std::fill( begin(), end(), x) ;
}
Vector( std::initializer_list<value_type> list ){
reset(list.size());
std::copy( list.begin(), list.end(), begin() ) ;
}
Vector( std::initializer_list<traits::named_object<value_type>> list ){
int n = list.size() ;
reset(n);
auto input_it = list.begin() ;
auto it = begin() ;
SEXP nams = PROTECT(Rf_allocVector(STRSXP, n) ) ;
for( int i=0; i<n; i++, ++it, ++input_it){
SET_STRING_ELT(nams, i, PRINTNAME(input_it->name) ) ;
*it = input_it->object ;
}
UNPROTECT(1) ;
names(*this) = nams ;
}
inline iterator begin() { return dataptr() ; }
inline iterator end() { return dataptr() + size() ; }
inline const_iterator begin() const{ return dataptr() ; }
inline const_iterator end() const{ return dataptr() + size() ; }
inline reference operator[](R_xlen_t i){
RCPP_CHECK_BOUNDS(i)
return dataptr()[i] ;
}
inline const_reference operator[](R_xlen_t i) const {
RCPP_CHECK_BOUNDS(i)
return dataptr()[i] ;
}
} ;
#undef VEC
}
#endif