Rcpp Version 1.1.2
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1// Vector.h: Rcpp R/C++ interface class library -- vectors
2//
3// Copyright (C) 2010 - 2026 Dirk Eddelbuettel and Romain Francois
4//
5// This file is part of Rcpp.
6//
7// Rcpp is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 2 of the License, or
10// (at your option) any later version.
11//
12// Rcpp is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19
20#ifndef Rcpp__vector__Vector_h
21#define Rcpp__vector__Vector_h
22
24#include <type_traits>
25
26namespace Rcpp{
27
28template <int RTYPE, template <class> class StoragePolicy = PreserveStorage >
29class Vector :
30 public StoragePolicy< Vector<RTYPE,StoragePolicy> >,
31 public SlotProxyPolicy< Vector<RTYPE,StoragePolicy> >,
32 public AttributeProxyPolicy< Vector<RTYPE,StoragePolicy> >,
33 public NamesProxyPolicy< Vector<RTYPE, StoragePolicy> >,
34 public RObjectMethods< Vector<RTYPE, StoragePolicy> >,
35 public VectorBase< RTYPE, true, Vector<RTYPE,StoragePolicy> >
36{
37public:
38
39 typedef StoragePolicy<Vector> Storage ;
40
51
57 Storage::set__( Rf_allocVector(RTYPE, 0 ) );
58 init() ;
59 }
60
64 Vector( const Vector& other){
65 Storage::copy__(other) ;
66 }
67
68 Vector& operator=(const Vector& rhs) {
69 return Storage::copy__(rhs) ;
70 }
71
72 Vector( SEXP x ) {
73 Rcpp::Shield<SEXP> safe(x);
74 Storage::set__( r_cast<RTYPE>(safe) ) ;
75 }
76
77 template <typename Proxy>
78 Vector( const GenericProxy<Proxy>& proxy ){
79 Rcpp::Shield<SEXP> safe(proxy.get());
80 Storage::set__( r_cast<RTYPE>(safe) ) ;
81 }
82
83 explicit Vector( const no_init_vector& obj) {
84 Storage::set__( Rf_allocVector( RTYPE, obj.get() ) ) ;
85 }
86
87 template<typename T>
88 Vector( const T& size, const stored_type& u,
90 RCPP_DEBUG_2( "Vector<%d>( const T& size = %d, const stored_type& u )", RTYPE, size)
91 Storage::set__( Rf_allocVector( RTYPE, size) ) ;
92 fill( u ) ;
93 }
94
95 Vector( const int& size, const stored_type& u) {
96 RCPP_DEBUG_2( "Vector<%d>( const int& size = %d, const stored_type& u )", RTYPE, size)
97 Storage::set__( Rf_allocVector( RTYPE, size) ) ;
98 fill( u ) ;
99 }
100
101 // constructor for CharacterVector()
102 Vector( const std::string& st ){
103 RCPP_DEBUG_2( "Vector<%d>( const std::string& = %s )", RTYPE, st.c_str() )
104 Storage::set__( internal::vector_from_string<RTYPE>(st) ) ;
105 }
106
107 // constructor for CharacterVector()
108 Vector( const char* st ) {
109 RCPP_DEBUG_2( "Vector<%d>( const char* = %s )", RTYPE, st )
110 Storage::set__(internal::vector_from_string<RTYPE>(st) ) ;
111 }
112
113 template<typename T>
114 Vector( const T& siz, stored_type (*gen)(void),
115 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
116 RCPP_DEBUG_2( "Vector<%d>( const int& siz = %s, stored_type (*gen)(void) )", RTYPE, siz )
117 Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
118 std::generate( begin(), end(), gen );
119 }
120
121 // Add template class T and then restict T to arithmetic.
122 template <typename T>
124 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
125 Storage::set__( Rf_allocVector( RTYPE, size) ) ;
126 init() ;
127 }
128
129 Vector( const int& size ) {
130 Storage::set__( Rf_allocVector( RTYPE, size) ) ;
131 init() ;
132 }
133
135 Storage::set__( Rf_allocVector( RTYPE, dims.prod() ) ) ;
136 init() ;
137 if( dims.size() > 1 ){
139 }
140 }
141
142 // Enable construction from bool for LogicalVectors
143 // SFINAE only work for template. Add template class T and then restict T to
144 // bool.
145 template <typename T>
146 Vector(T value,
147 typename Rcpp::traits::enable_if<traits::is_bool<T>::value && RTYPE == LGLSXP, void>::type* = 0) {
148 Storage::set__(Rf_allocVector(RTYPE, 1));
149 fill(value);
150 }
151
152 template <typename U>
153 Vector( const Dimension& dims, const U& u) {
154 RCPP_DEBUG_2( "Vector<%d>( const Dimension& (%d), const U& )", RTYPE, dims.size() )
155 Storage::set__( Rf_allocVector( RTYPE, dims.prod() ) ) ;
156 fill(u) ;
157 if( dims.size() > 1 ){
159 }
160 }
161
162 template <bool NA, typename VEC>
164 RCPP_DEBUG_2( "Vector<%d>( const VectorBase<RTYPE,NA,VEC>& ) [VEC = %s]", RTYPE, DEMANGLE(VEC) )
166 }
167
168 template <typename T, typename U>
169 Vector( const T& size, const U& u,
170 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
171 RCPP_DEBUG_2( "Vector<%d>( const T& size, const U& u )", RTYPE, size )
172 Storage::set__( Rf_allocVector( RTYPE, size) ) ;
173 fill_or_generate( u ) ;
174 }
175
176 template <bool NA, typename T>
178 Rcpp::Shield<SEXP> safe(const_cast<sugar::SingleLogicalResult<NA,T>&>(obj).get_sexp() );
179 Storage::set__( r_cast<RTYPE>(safe) ) ;
180 RCPP_DEBUG_2( "Vector<%d>( const sugar::SingleLogicalResult<NA,T>& ) [T = %s]", RTYPE, DEMANGLE(T) )
181 }
182
183 template <typename T, typename U1>
184 Vector( const T& siz, stored_type (*gen)(U1), const U1& u1,
185 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
186 Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
187 RCPP_DEBUG_2( "const T& siz, stored_type (*gen)(U1), const U1& u1 )", RTYPE, siz )
188 iterator first = begin(), last = end() ;
189 while( first != last ) *first++ = gen(u1) ;
190 }
191
192 template <typename T, typename U1, typename U2>
193 Vector( const T& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2,
194 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
195 Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
196 RCPP_DEBUG_2( "const T& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2)", RTYPE, siz )
197 iterator first = begin(), last = end() ;
198 while( first != last ) *first++ = gen(u1,u2) ;
199 }
200
201 template <typename T, typename U1, typename U2, typename U3>
202 Vector( const T& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3,
203 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
204 Storage::set__( Rf_allocVector( RTYPE, siz) ) ;
205 RCPP_DEBUG_2( "const T& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3)", RTYPE, siz )
206 iterator first = begin(), last = end() ;
207 while( first != last ) *first++ = gen(u1,u2,u3) ;
208 }
209
210 template <typename InputIterator>
211 Vector( InputIterator first, InputIterator last){
212 RCPP_DEBUG_1( "Vector<%d>( InputIterator first, InputIterator last", RTYPE )
213 Storage::set__( Rf_allocVector(RTYPE, std::distance(first, last) ) ) ;
214 std::copy( first, last, begin() ) ;
215 }
216
217 template <typename InputIterator, typename T>
218 Vector( InputIterator first, InputIterator last, T n,
219 typename Rcpp::traits::enable_if<traits::is_arithmetic<T>::value, void>::type* = 0) {
220 Storage::set__(Rf_allocVector(RTYPE, n)) ;
221 RCPP_DEBUG_2( "Vector<%d>( InputIterator first, InputIterator last, T n = %d)", RTYPE, n )
222 std::copy( first, last, begin() ) ;
223 }
224
225 template <typename InputIterator, typename Func>
226 Vector( InputIterator first, InputIterator last, Func func) {
227 Storage::set__( Rf_allocVector( RTYPE, std::distance(first,last) ) );
228 RCPP_DEBUG_1( "Vector<%d>( InputIterator, InputIterator, Func )", RTYPE )
229 std::transform( first, last, begin(), func) ;
230 }
231
232 template <typename InputIterator, typename Func, typename T>
233 Vector( InputIterator first, InputIterator last, Func func, T n,
235 Storage::set__( Rf_allocVector( RTYPE, n ) );
236 RCPP_DEBUG_2( "Vector<%d>( InputIterator, InputIterator, Func, T n = %d )", RTYPE, n )
237 std::transform( first, last, begin(), func) ;
238 }
239
240 Vector( std::initializer_list<init_type> list ) {
241 assign( list.begin() , list.end() ) ;
242 }
243
244 template <typename T>
245 Vector& operator=( const T& x) {
247 return *this ;
248 }
249
250 static inline stored_type get_na() {
251 return traits::get_na<RTYPE>();
252 }
253 static inline bool is_na( stored_type x){
254 return traits::is_na<RTYPE>(x);
255 }
256
257 #ifdef RCPP_COMMA_INITIALIZATION
258 internal::ListInitialization<iterator,init_type> operator=( init_type x){
259 iterator start = begin() ; *start = x;
260 return internal::ListInitialization<iterator,init_type>( start + 1 ) ; ;
261 }
262 #endif
263
267 inline R_xlen_t length() const {
268 return ::Rf_xlength( Storage::get__() ) ;
269 }
270
274 inline R_xlen_t size() const {
275 return ::Rf_xlength( Storage::get__() ) ;
276 }
277
281 R_xlen_t offset(const int& i, const int& j) const {
282 if( !::Rf_isMatrix(Storage::get__()) ) throw not_a_matrix() ;
283
284 /* we need to extract the dimensions */
285 const int* dim = dims() ;
286 const int nrow = dim[0] ;
287 const int ncol = dim[1] ;
288 if(i < 0|| i >= nrow || j < 0 || j >= ncol ) {
289 const char* fmt = "Location index is out of bounds: "
290 "[row index=%i; row extent=%i; "
291 "column index=%i; column extent=%i].";
292 throw index_out_of_bounds(fmt, i, nrow, j, ncol);
293 }
294 return i + static_cast<R_xlen_t>(nrow)*j ;
295 }
296
301 R_xlen_t offset(const R_xlen_t& i) const { // #nocov start
302 if(i < 0 || i >= ::Rf_xlength(Storage::get__()) ) {
303 const char* fmt = "Index out of bounds: [index=%i; extent=%i].";
304 throw index_out_of_bounds(fmt, i, ::Rf_xlength(Storage::get__()) ) ;
305 }
306 return i ; // #nocov end
307 }
308
309 R_xlen_t offset(const std::string& name) const {
310 SEXP names = RCPP_GET_NAMES( Storage::get__() ) ;
311 if( Rf_isNull(names) ) {
312 throw index_out_of_bounds("Object was created without names.");
313 }
314
315 R_xlen_t n=size() ;
316 for( R_xlen_t i=0; i<n; ++i){
317 if( ! name.compare( CHAR(STRING_ELT(names, i)) ) ){
318 return i ;
319 }
320 }
321
322 const char* fmt = "Index out of bounds: [index='%s'].";
323 throw index_out_of_bounds(fmt, name);
324 return -1 ; /* -Wall */
325 }
326
327 template <typename U>
328 void fill( const U& u){
330 }
331
332 inline iterator begin() { return cache.get() ; }
333 inline iterator end() { return cache.get() + size(); }
334 inline const_iterator begin() const{ return cache.get_const() ; }
335 inline const_iterator end() const{ return cache.get_const() + size() ; }
336 inline const_iterator cbegin() const{ return cache.get_const() ; }
337 inline const_iterator cend() const{ return cache.get_const() + size() ; }
338
339 inline Proxy operator[]( R_xlen_t i ){ return cache.ref(i) ; }
340 inline const_Proxy operator[]( R_xlen_t i ) const { return cache.ref(i) ; }
341#ifndef LONG_VECTOR_SUPPORT
342 // On platforms without long vector support (notably wasm32) R_xlen_t is
343 // int while ptrdiff_t is long, so subscripting with any wider integer
344 // type would otherwise be ambiguous with the built-in pointer subscript
345 // synthesised via the implicit Vector -> SEXP conversion. The template
346 // overloads below provide an exact-match member candidate for every
347 // integer index type other than R_xlen_t itself.
348 template <typename T>
349 inline typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, R_xlen_t>::value, Proxy>::type
350 operator[]( T i ){ return cache.ref(static_cast<R_xlen_t>(i)) ; }
351 template <typename T>
352 inline typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, R_xlen_t>::value, const_Proxy>::type
353 operator[]( T i ) const { return cache.ref(static_cast<R_xlen_t>(i)) ; }
354#endif
355
356 inline Proxy operator()( const size_t& i) {
357 return cache.ref( offset(i) ) ;
358 }
359 inline const_Proxy operator()( const size_t& i) const {
360 return cache.ref( offset(i) ) ;
361 }
362
363 inline Proxy at( const size_t& i) { // #nocov start
364 return cache.ref( offset(i) ) ;
365 }
366 inline const_Proxy at( const size_t& i) const {
367 return cache.ref( offset(i) ) ;
368 } // #nocov end
369
370 inline Proxy operator()( const size_t& i, const size_t& j) {
371 return cache.ref( offset(i,j) ) ;
372 }
373 inline const_Proxy operator()( const size_t& i, const size_t& j) const {
374 return cache.ref( offset(i,j) ) ;
375 }
376
377 inline NameProxy operator[]( const std::string& name ){
378 return NameProxy( *this, name ) ;
379 }
380 inline NameProxy operator()( const std::string& name ){
381 return NameProxy( *this, name ) ;
382 }
383
384 inline NameProxy operator[]( const std::string& name ) const {
385 return NameProxy( const_cast<Vector&>(*this), name ) ;
386 }
387 inline NameProxy operator()( const std::string& name ) const {
388 return NameProxy( const_cast<Vector&>(*this), name ) ;
389 }
390
391 inline operator RObject() const {
392 return RObject( Storage::get__() );
393 }
394
395 // sugar subsetting requires dispatch on VectorBase
396 template <int RHS_RTYPE, bool RHS_NA, typename RHS_T>
404
405 template <int RHS_RTYPE, bool RHS_NA, typename RHS_T>
413
414 Vector& sort(bool decreasing = false) {
415 // sort() does not apply to List, RawVector or ExpressionVector.
416 //
417 // The function below does nothing for qualified Vector types,
418 // and is undefined for other types. Hence there will be a
419 // compiler error when sorting List, RawVector or ExpressionVector.
420 internal::Sort_is_not_allowed_for_this_type<RTYPE>::do_nothing();
421
422 typename traits::storage_type<RTYPE>::type* start = internal::r_vector_start<RTYPE>( Storage::get__() );
423
424 if (!decreasing) {
425 std::sort(
426 start,
427 start + size(),
428 internal::NAComparator<typename traits::storage_type<RTYPE>::type>()
429 );
430 } else {
431 std::sort(
432 start,
433 start + size(),
434 internal::NAComparatorGreater<typename traits::storage_type<RTYPE>::type>()
435 );
436 }
437
438 return *this;
439 }
440
441 template <typename InputIterator>
442 void assign( InputIterator first, InputIterator last){
443 /* FIXME: we can do better than this r_cast to avoid
444 allocating an unnecessary temporary object
445 */
446 Shield<SEXP> wrapped(wrap(first, last));
447 Shield<SEXP> casted(r_cast<RTYPE>(wrapped));
448 Storage::set__(casted) ;
449 }
450
451 template <typename InputIterator>
452 static Vector import( InputIterator first, InputIterator last){
453 Vector v ;
454 v.assign( first , last ) ;
455 return v ;
456 }
457
458 template <typename InputIterator, typename F>
459 static Vector import_transform( InputIterator first, InputIterator last, F f){
460 return Vector( first, last, f) ;
461 }
462
463 template <typename T>
464 void push_back( const T& object){
467 ) ;
468 }
469
470 template <typename T>
471 void push_back( const T& object, const std::string& name ){
474 ) ;
475 }
476
477 template <typename T>
478 void push_front( const T& object){
481 }
482
483 template <typename T>
484 void push_front( const T& object, const std::string& name){
487 }
488
489
490 template <typename T>
491 iterator insert( iterator position, const T& object){
492 return insert__impl( position, converter_type::get(object),
494 ) ;
495 }
496
497 template <typename T>
498 iterator insert( int position, const T& object){
499 return insert__impl( cache.get() + position, converter_type::get(object),
501 );
502 }
503
504 iterator erase( int position){
505 return erase_single__impl( cache.get() + position) ;
506 }
507
509 return erase_single__impl( position ) ;
510 }
511
512 iterator erase( int first, int last){
513 iterator start = cache.get() ;
514 return erase_range__impl( start + first, start + last ) ;
515 }
516
518 return erase_range__impl( first, last ) ;
519 }
520
521 void update(SEXP){
522 cache.update(*this) ;
523 }
524
525 template <typename U>
526 static void replace_element( iterator it, SEXP names, R_xlen_t index, const U& u){
528 it, names, index, u ) ;
529 }
530
531 template <typename U>
532 static void replace_element__dispatch( traits::false_type, iterator it, SEXP names, R_xlen_t index, const U& u){
533 *it = converter_type::get(u);
534 }
535
536 template <typename U>
537 static void replace_element__dispatch( traits::true_type, iterator it, SEXP names, R_xlen_t index, const U& u){
539 }
540
541 template <typename U>
542 static void replace_element__dispatch__isArgument( traits::false_type, iterator it, SEXP names, R_xlen_t index, const U& u){
543 RCPP_DEBUG_2( " Vector::replace_element__dispatch<%s>(true, index= %d) ", DEMANGLE(U), index ) ;
544
545 *it = converter_type::get(u.object ) ;
546 SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
547 }
548
549 template <typename U>
550 static void replace_element__dispatch__isArgument( traits::true_type, iterator it, SEXP names, R_xlen_t index, const U& u){
551 RCPP_DEBUG_2( " Vector::replace_element__dispatch<%s>(true, index= %d) ", DEMANGLE(U), index ) ;
552
553 *it = R_MissingArg ;
554 SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
555 }
556
558
559 inline Indexer operator[]( const Range& range ){
560 return Indexer( const_cast<Vector&>(*this), range );
561 }
562
563 template <typename EXPR_VEC>
565 const EXPR_VEC& ref = rhs.get_ref() ;
566 iterator start = begin() ;
567 R_xlen_t n = size() ;
568 // TODO: maybe unroll this
569 stored_type tmp ;
570 for( R_xlen_t i=0; i<n; i++){
571 Proxy left = start[i] ;
572 if( ! traits::is_na<RTYPE>( left ) ){
573 tmp = ref[i] ;
574 left = traits::is_na<RTYPE>( tmp ) ? tmp : ( left + tmp ) ;
575 }
576 }
577 return *this ;
578 }
579
580 template <typename EXPR_VEC>
582 const EXPR_VEC& ref = rhs.get_ref() ;
583 iterator start = begin() ;
584 R_xlen_t n = size() ;
585 stored_type tmp ;
586 for( R_xlen_t i=0; i<n; i++){
587 if( ! traits::is_na<RTYPE>(start[i]) ){
588 start[i] += ref[i] ;
589 }
590 }
591 return *this ;
592
593 }
594
598 bool containsElementNamed( const char* target ) const {
599 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
600 if( Rf_isNull(names) ) return false ;
601 R_xlen_t n = Rf_xlength(names) ;
602 for( R_xlen_t i=0; i<n; i++){
603 if( !strcmp( target, CHAR(STRING_ELT(names, i)) ) )
604 return true ;
605 }
606 return false ;
607 }
608
609 R_xlen_t findName(const std::string& name) const {
610 SEXP names = RCPP_GET_NAMES(Storage::get__());
611 if (Rf_isNull(names)) stop("'names' attribute is null");
612 R_xlen_t n = Rf_xlength(names);
613 for (R_xlen_t i=0; i < n; ++i) {
614 if (strcmp(name.c_str(), CHAR(STRING_ELT(names, i))) == 0) {
615 return i;
616 }
617 }
618 std::stringstream ss;
619 ss << "no name '" << name << "' found";
620 stop(ss.str());
621 return -1;
622 }
623
624protected:
625 inline int* dims() const {
626 if( !::Rf_isMatrix(Storage::get__()) ) throw not_a_matrix() ;
627 return INTEGER( ::Rf_getAttrib( Storage::get__(), R_DimSymbol ) ) ;
628 }
629 void init(){
630 RCPP_DEBUG_2( "VECTOR<%d>::init( SEXP = <%p> )", RTYPE, Storage::get__() )
631 internal::r_init_vector<RTYPE>(Storage::get__()) ;
632 }
633
634private:
635
637 Shield<SEXP> object_sexp( object ) ;
638 R_xlen_t n = size() ;
639 Vector target( n + 1 ) ;
640 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
641 iterator target_it( target.begin() ) ;
642 iterator it(begin()) ;
643 iterator this_end(end());
644 if( Rf_isNull(names) ){
645 for( ; it < this_end; ++it, ++target_it ){
646 *target_it = *it ; // #nocov start
647 }
648 } else {
649 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) ) ;
650 int i = 0 ;
651 for( ; it < this_end; ++it, ++target_it, i++ ){
652 *target_it = *it ;
653 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
654 }
655 SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
656 target.attr("names") = newnames ; // #nocov end
657 }
658 *target_it = object_sexp;
659 Storage::set__( target.get__() ) ;
660 }
661
663 R_xlen_t n = size() ;
664 Vector target( n + 1 ) ;
665 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
666 iterator target_it( target.begin() ) ;
667 iterator it(begin()) ;
668 iterator this_end(end());
669 if( Rf_isNull(names) ){
670 for( ; it < this_end; ++it, ++target_it ){
671 *target_it = *it ;
672 }
673 } else {
674 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) ) ;
675 int i = 0 ;
676 for( ; it < this_end; ++it, ++target_it, i++ ){
677 *target_it = *it ;
678 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
679 }
680 SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
681 target.attr("names") = newnames ;
682 }
683 *target_it = object;
684 Storage::set__( target.get__() ) ;
685 }
686
687 void push_back_name__impl(const stored_type& object, const std::string& name, traits::true_type ) {
688 Shield<SEXP> object_sexp( object ) ;
689 R_xlen_t n = size() ;
690 Vector target( n + 1 ) ;
691 iterator target_it( target.begin() ) ;
692 iterator it(begin()) ;
693 iterator this_end(end());
694 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
695 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
696 int i=0;
697 if( Rf_isNull(names) ){
698 for( ; it < this_end; ++it, ++target_it,i++ ){
699 *target_it = *it ; // #nocov
700 SET_STRING_ELT( newnames, i , R_BlankString ); // #nocov
701 }
702 } else {
703 for( ; it < this_end; ++it, ++target_it, i++ ){
704 *target_it = *it ;
705 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
706 }
707 }
708 SET_STRING_ELT( newnames, i, Rf_mkChar( name.c_str() ) );
709 target.attr("names") = newnames ;
710
711 *target_it = object_sexp;
712 Storage::set__( target.get__() ) ;
713 }
714 void push_back_name__impl(const stored_type& object, const std::string& name, traits::false_type ) {
715 R_xlen_t n = size() ;
716 Vector target( n + 1 ) ;
717 iterator target_it( target.begin() ) ;
718 iterator it(begin()) ;
719 iterator this_end(end());
720 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
721 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
722 int i=0;
723 if( Rf_isNull(names) ){
724 Shield<SEXP> dummy( Rf_mkChar("") );
725 for( ; it < this_end; ++it, ++target_it,i++ ){
726 *target_it = *it ;
727 SET_STRING_ELT( newnames, i , dummy );
728 }
729 } else {
730 for( ; it < this_end; ++it, ++target_it, i++ ){
731 *target_it = *it ;
732 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
733 }
734 }
735 SET_STRING_ELT( newnames, i, Rf_mkChar( name.c_str() ) );
736 target.attr("names") = newnames ;
737
738 *target_it = object;
739 Storage::set__( target.get__() ) ;
740 }
741
743 Shield<SEXP> object_sexp( object ) ;
744 R_xlen_t n = size() ;
745 Vector target( n+1);
746 iterator target_it(target.begin());
747 iterator it(begin());
748 iterator this_end(end());
749 *target_it = object_sexp ;
750 ++target_it ;
751 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
752 if( Rf_isNull(names) ){
753 for( ; it<this_end; ++it, ++target_it){
754 *target_it = *it ;
755 }
756 } else{
757 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) );
758 int i=1 ;
759 SET_STRING_ELT( newnames, 0, Rf_mkChar("") ) ;
760 for( ; it<this_end; ++it, ++target_it, i++){
761 *target_it = *it ;
762 SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
763 }
764 target.attr("names") = newnames ;
765 }
766 Storage::set__( target.get__() ) ;
767
768 }
770 R_xlen_t n = size() ;
771 Vector target( n+1);
772 iterator target_it(target.begin());
773 iterator it(begin());
774 iterator this_end(end());
775 *target_it = object ;
776 ++target_it ;
777 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
778 if( Rf_isNull(names) ){
779 for( ; it<this_end; ++it, ++target_it){
780 *target_it = *it ;
781 }
782 } else{
783 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) );
784 int i=1 ;
785 SET_STRING_ELT( newnames, 0, Rf_mkChar("") ) ;
786 for( ; it<this_end; ++it, ++target_it, i++){
787 *target_it = *it ;
788 SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
789 }
790 target.attr("names") = newnames ;
791 }
792 Storage::set__( target.get__() ) ;
793
794 }
795
796 void push_front_name__impl(const stored_type& object, const std::string& name, traits::true_type ) {
797 Shield<SEXP> object_sexp(object) ;
798 R_xlen_t n = size() ;
799 Vector target( n + 1 ) ;
800 iterator target_it( target.begin() ) ;
801 iterator it(begin()) ;
802 iterator this_end(end());
803 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
804 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
805 int i=1;
806 SET_STRING_ELT( newnames, 0, Rf_mkChar( name.c_str() ) );
807 *target_it = object_sexp;
808 ++target_it ;
809
810 if( Rf_isNull(names) ){
811 for( ; it < this_end; ++it, ++target_it,i++ ){
812 *target_it = *it ;
813 SET_STRING_ELT( newnames, i , R_BlankString );
814 }
815 } else {
816 for( ; it < this_end; ++it, ++target_it, i++ ){
817 *target_it = *it ;
818 SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
819 }
820 }
821 target.attr("names") = newnames ;
822 Storage::set__( target.get__() ) ;
823
824 }
825 void push_front_name__impl(const stored_type& object, const std::string& name, traits::false_type ) {
826 R_xlen_t n = size() ;
827 Vector target( n + 1 ) ;
828 iterator target_it( target.begin() ) ;
829 iterator it(begin()) ;
830 iterator this_end(end());
831 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
832 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
833 int i=1;
834 SET_STRING_ELT( newnames, 0, Rf_mkChar( name.c_str() ) );
835 *target_it = object;
836 ++target_it ;
837
838 if( Rf_isNull(names) ){
839 for( ; it < this_end; ++it, ++target_it,i++ ){
840 *target_it = *it ;
841 SET_STRING_ELT( newnames, i , R_BlankString );
842 }
843 } else {
844 for( ; it < this_end; ++it, ++target_it, i++ ){
845 *target_it = *it ;
846 SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
847 }
848 }
849 target.attr("names") = newnames ;
850
851 Storage::set__( target.get__() ) ;
852
853 }
854
856 Shield<SEXP> object( object_ ) ;
857 R_xlen_t n = size() ;
858 Vector target( n+1 ) ;
859 iterator target_it = target.begin();
860 iterator it = begin() ;
861 iterator this_end = end() ;
862 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
864 if( Rf_isNull(names) ){
865 for( ; it < position; ++it, ++target_it){
866 *target_it = *it ;
867 }
868 result = target_it;
869 *target_it = object ;
870 ++target_it ;
871 for( ; it < this_end; ++it, ++target_it ){
872 *target_it = *it ;
873 }
874 } else{
875 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1 ) ) ;
876 int i=0;
877 for( ; it < position; ++it, ++target_it, i++){
878 *target_it = *it ;
879 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
880 }
881 result = target_it;
882 *target_it = object ;
883 SET_STRING_ELT( newnames, i, ::Rf_mkChar("") ) ;
884 i++ ;
885 ++target_it ;
886 for( ; it < this_end; ++it, ++target_it, i++ ){
887 *target_it = *it ;
888 SET_STRING_ELT( newnames, i, STRING_ELT(names, i - 1) ) ;
889 }
890 target.attr( "names" ) = newnames ;
891 }
892 Storage::set__( target.get__() ) ;
893 return result ;
894 }
895
897 R_xlen_t n = size() ;
898 Vector target( n+1 ) ;
899 iterator target_it = target.begin();
900 iterator it = begin() ;
901 iterator this_end = end() ;
902 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
904 if( Rf_isNull(names) ){
905 for( ; it < position; ++it, ++target_it){
906 *target_it = *it ;
907 }
908 result = target_it;
909 *target_it = object ;
910 ++target_it ;
911 for( ; it < this_end; ++it, ++target_it ){
912 *target_it = *it ;
913 }
914 } else{
915 Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1 ) ) ;
916 int i=0;
917 for( ; it < position; ++it, ++target_it, i++){
918 *target_it = *it ;
919 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
920 }
921 result = target_it;
922 *target_it = object ;
923 SET_STRING_ELT( newnames, i, ::Rf_mkChar("") ) ;
924 i++ ;
925 ++target_it ;
926 for( ; it < this_end; ++it, ++target_it, i++ ){
927 *target_it = *it ;
928 SET_STRING_ELT( newnames, i, STRING_ELT(names, i - 1) ) ;
929 }
930 target.attr( "names" ) = newnames ;
931 }
932 Storage::set__( target.get__() ) ;
933 return result ;
934 }
935
937 if( position < begin() || position > end() ) {
938 R_xlen_t requested_loc;
939 R_xlen_t available_locs = std::distance(begin(), end());
940
941 if(position > end()){
942 requested_loc = std::distance(position, begin());
943 } else {
944 // This will be a negative number
945 requested_loc = std::distance(begin(), position);
946 }
947 const char* fmt = "Iterator index is out of bounds: "
948 "[iterator index=%i; iterator extent=%i]";
949 throw index_out_of_bounds(fmt, requested_loc, available_locs ) ;
950 }
951
952 R_xlen_t n = size() ;
953
954 Vector target( n - 1 ) ;
955 iterator target_it(target.begin()) ;
956 iterator it(begin()) ;
957 iterator this_end(end()) ;
958 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
959 if( Rf_isNull(names) ){
960 int i=0;
961 for( ; it < position; ++it, ++target_it, i++){
962 *target_it = *it;
963 }
964 ++it ;
965 for( ; it < this_end ; ++it, ++target_it){
966 *target_it = *it;
967 }
968 Storage::set__( target.get__() ) ;
969 return begin()+i ;
970 } else {
971 Shield<SEXP> newnames(::Rf_allocVector( STRSXP, n-1 ));
972 int i= 0 ;
973 for( ; it < position; ++it, ++target_it,i++){
974 *target_it = *it;
975 SET_STRING_ELT( newnames, i , STRING_ELT(names,i) ) ;
976 }
977 int result=i ;
978 ++it ;
979 i++ ;
980 for( ; it < this_end ; ++it, ++target_it, i++){
981 *target_it = *it;
982 SET_STRING_ELT( newnames, i-1, STRING_ELT(names,i) ) ;
983 }
984 target.attr( "names" ) = newnames ;
985 Storage::set__( target.get__() ) ;
986 return begin()+result ;
987 }
988 }
989
991 if( first > last ) throw std::range_error("invalid range") ;
992 if( last > end() || first < begin() ) {
993 R_xlen_t requested_loc;
994 R_xlen_t available_locs = std::distance(begin(), end());
995 std::string iter_problem;
996
997 if(last > end()){
998 requested_loc = std::distance(last, begin());
999 iter_problem = "last";
1000 } else {
1001 // This will be a negative number
1002 requested_loc = std::distance(begin(), first);
1003 iter_problem = "first";
1004 }
1005 const char* fmt = "Iterator index is out of bounds: "
1006 "[iterator=%s; index=%i; extent=%i]";
1007 throw index_out_of_bounds(fmt, iter_problem,
1008 requested_loc, available_locs ) ;
1009 }
1010
1011 iterator it = begin() ;
1012 iterator this_end = end() ;
1013 R_xlen_t nremoved = std::distance(first,last) ;
1014 R_xlen_t target_size = size() - nremoved ;
1015 Vector target( target_size ) ;
1016 iterator target_it = target.begin() ;
1017
1018 SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
1019 int result = 0;
1020 if( Rf_isNull(names) ){
1021 int i=0;
1022 for( ; it < first; ++it, ++target_it, i++ ){
1023 *target_it = *it ;
1024 }
1025 result = i;
1026 for( it = last ; it < this_end; ++it, ++target_it ){
1027 *target_it = *it ;
1028 }
1029 } else{
1030 Shield<SEXP> newnames( ::Rf_allocVector(STRSXP, target_size) ) ;
1031 int i= 0 ;
1032 for( ; it < first; ++it, ++target_it, i++ ){
1033 *target_it = *it ;
1034 SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) );
1035 }
1036 result = i;
1037 for( it = last ; it < this_end; ++it, ++target_it, i++ ){
1038 *target_it = *it ;
1039 SET_STRING_ELT( newnames, i, STRING_ELT(names, i + nremoved ) );
1040 }
1041 target.attr("names" ) = newnames ;
1042 }
1043 Storage::set__( target.get__() ) ;
1044
1045 return begin() + result;
1046
1047 }
1048
1049 template <typename T>
1050 inline void assign_sugar_expression( const T& x ) {
1051 R_xlen_t n = size() ;
1052 if( n == x.size() ){
1053 // just copy the data
1054 import_expression<T>(x, n ) ;
1055 } else{
1056 // different size, so we change the memory
1057 Shield<SEXP> wrapped(wrap(x));
1058 Shield<SEXP> casted(r_cast<RTYPE>(wrapped));
1059 Storage::set__(casted);
1060 }
1061 }
1062
1063 // sugar
1064 template <typename T>
1065 inline void assign_object( const T& x, traits::true_type ) {
1066 assign_sugar_expression( x.get_ref() ) ;
1067 }
1068
1069 // anything else
1070 template <typename T>
1071 inline void assign_object( const T& x, traits::false_type ) {
1072 Shield<SEXP> wrapped(wrap(x));
1073 Shield<SEXP> casted(r_cast<RTYPE>(wrapped));
1074 Storage::set__(casted);
1075 }
1076
1077 // we are importing a real sugar expression, i.e. not a vector
1078 template <bool NA, typename VEC>
1080 RCPP_DEBUG_4( "Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, false_type )", RTYPE, NA, RTYPE, DEMANGLE(VEC) ) ;
1081 R_xlen_t n = other.size() ;
1082 Storage::set__( Rf_allocVector( RTYPE, n ) ) ;
1083 import_expression<VEC>( other.get_ref() , n ) ;
1084 }
1085
1086 // we are importing a sugar expression that actually is a vector
1087 template <bool NA, typename VEC>
1089 RCPP_DEBUG_4( "Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, true_type )", RTYPE, NA, RTYPE, DEMANGLE(VEC) ) ;
1090 Storage::set__( other.get_ref() ) ;
1091 }
1092
1093
1094 template <typename T>
1095 inline void import_expression( const T& other, R_xlen_t n ) {
1096 iterator start = begin() ;
1097 RCPP_LOOP_UNROLL(start,other)
1098 }
1099
1100 template <typename T>
1101 inline void fill_or_generate( const T& t) {
1103 }
1104
1105 template <typename T>
1106 inline void fill_or_generate__impl( const T& gen, traits::true_type) {
1107 iterator first = begin() ;
1108 iterator last = end() ;
1109 while( first != last ) *first++ = gen() ;
1110 }
1111
1112 template <typename T>
1113 inline void fill_or_generate__impl( const T& t, traits::false_type) {
1114 fill(t) ;
1115 }
1116
1117 template <typename U>
1119 // when this is not trivial, this is SEXP
1120 Shield<SEXP> elem( converter_type::get( u ) );
1121 iterator it(begin());
1122 for( R_xlen_t i=0; i<size() ; i++, ++it){
1123 *it = ::Rf_duplicate( elem ) ;
1124 }
1125 }
1126
1127 template <typename U>
1129 std::fill( begin(), end(), converter_type::get( u ) ) ;
1130 }
1131
1132public:
1133
1134 static Vector create(){
1135 return Vector( 0 ) ;
1136 }
1137
1138public:
1139 template <typename... T>
1140 static Vector create(const T&... t){
1141 return create__dispatch( typename traits::integral_constant<bool,
1143 >::type(), t... ) ;
1144 }
1145
1146private:
1147 template <typename... T>
1149 Vector res(sizeof...(T)) ;
1150 iterator it(res.begin());
1151 create_dispatch_impl(it, t...);
1152 return res;
1153 }
1154
1155 template <typename... T>
1157 Vector res(sizeof...(T)) ;
1158 Shield<SEXP> names(::Rf_allocVector(STRSXP, sizeof...(T)));
1159 int index = 0;
1160 iterator it(res.begin());
1161 replace_element_impl(it, names, index, t...);
1162 res.attr("names") = names;
1163 return res;
1164 }
1165
1166 template <typename T>
1167 static void create_dispatch_impl(iterator& it, const T& t) {
1168 *it = converter_type::get(t);
1169 }
1170
1171 template <typename T, typename... TArgs>
1172 static void create_dispatch_impl(iterator& it, const T& t, const TArgs&... args) {
1173 *it = converter_type::get(t);
1174 create_dispatch_impl(++it, args...);
1175 }
1176
1177 template <typename T>
1178 static void replace_element_impl(iterator& it, Shield<SEXP>& names, int& index, const T& t) {
1179 replace_element(it, names, index, t);
1180 }
1181
1182 template <typename T, typename... TArgs>
1183 static void replace_element_impl(iterator& it, Shield<SEXP>& names, int& index, const T& t, const TArgs&... args) {
1184 replace_element(it, names, index, t);
1185 replace_element_impl(++it, names, ++index, args...);
1186 }
1187
1188public:
1189
1190 inline SEXP eval() const {
1191 return Rcpp_eval( Storage::get__(), R_GlobalEnv ) ;
1192 }
1193
1194 inline SEXP eval(SEXP env) const {
1195 return Rcpp_eval( Storage::get__(), env );
1196 }
1197
1198
1199} ; /* Vector */
1200
1201template <int RTYPE, template <class> class StoragePolicy >
1202inline std::ostream &operator<<(std::ostream & s, const Vector<RTYPE, StoragePolicy> & rhs) {
1203 typedef Vector<RTYPE, StoragePolicy> VECTOR;
1204
1205 typename VECTOR::iterator i = const_cast<VECTOR &>(rhs).begin();
1206 typename VECTOR::iterator iend = const_cast<VECTOR &>(rhs).end();
1207
1208 if (i != iend) {
1209 s << (*i);
1210 ++i;
1211
1212 for ( ; i != iend; ++i) {
1213 s << " " << (*i);
1214 }
1215 }
1216
1217 return s;
1218}
1219
1220template<template <class> class StoragePolicy >
1221inline std::ostream &operator<<(std::ostream & s, const Vector<STRSXP, StoragePolicy> & rhs) {
1222 typedef Vector<STRSXP, StoragePolicy> VECTOR;
1223
1224 typename VECTOR::iterator i = const_cast<VECTOR &>(rhs).begin();
1225 typename VECTOR::iterator iend = const_cast<VECTOR &>(rhs).end();
1226
1227 if (i != iend) {
1228 s << "\"" << (*i) << "\"";
1229 ++i;
1230
1231 for ( ; i != iend; ++i) {
1232 s << " \"" << (*i) << "\"";
1233 }
1234 }
1235
1236 return s;
1237}
1238
1239}
1240
1241#endif
AttributeProxy attr(const std::string &name)
R_xlen_t size() const
Definition VectorBase.h:49
VECTOR & get_ref()
Definition VectorBase.h:37
void fill_or_generate__impl(const T &t, traits::false_type)
Definition Vector.h:1113
traits::storage_type< RTYPE >::type stored_type
Definition Vector.h:50
void fill_or_generate(const T &t)
Definition Vector.h:1101
iterator erase_range__impl(iterator first, iterator last)
Definition Vector.h:990
static Vector import_transform(InputIterator first, InputIterator last, F f)
Definition Vector.h:459
iterator erase(int position)
Definition Vector.h:504
internal::RangeIndexer< RTYPE, true, Vector > Indexer
Definition Vector.h:557
Vector & operator=(const T &x)
Definition Vector.h:245
SEXP eval(SEXP env) const
Definition Vector.h:1194
Vector(const GenericProxy< Proxy > &proxy)
Definition Vector.h:78
Vector(std::initializer_list< init_type > list)
Definition Vector.h:240
Vector(const T &size, const U &u, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:169
Vector(const Dimension &dims)
Definition Vector.h:134
R_xlen_t findName(const std::string &name) const
Definition Vector.h:609
Vector(const T &size, const stored_type &u, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:88
void push_front_name__impl(const stored_type &object, const std::string &name, traits::false_type)
Definition Vector.h:825
void import_sugar_expression(const Rcpp::VectorBase< RTYPE, NA, VEC > &other, traits::true_type)
Definition Vector.h:1088
void push_back__impl(const stored_type &object, traits::true_type)
Definition Vector.h:636
iterator erase_single__impl(iterator position)
Definition Vector.h:936
traits::r_vector_cache_type< RTYPE, StoragePolicy >::type cache
Definition Vector.h:41
Vector(SEXP x)
Definition Vector.h:72
std::enable_if< std::is_integral< T >::value &&!std::is_same< T, R_xlen_t >::value, const_Proxy >::type operator[](T i) const
Definition Vector.h:353
const_Proxy operator[](R_xlen_t i) const
Definition Vector.h:340
Vector & operator+=(const VectorBase< RTYPE, false, EXPR_VEC > &rhs)
Definition Vector.h:581
void assign(InputIterator first, InputIterator last)
Definition Vector.h:442
Vector & operator+=(const VectorBase< RTYPE, true, EXPR_VEC > &rhs)
Definition Vector.h:564
void push_back_name__impl(const stored_type &object, const std::string &name, traits::true_type)
Definition Vector.h:687
static Vector create(const T &... t)
Definition Vector.h:1140
Vector(const std::string &st)
Definition Vector.h:102
const_iterator begin() const
Definition Vector.h:334
NameProxy operator[](const std::string &name) const
Definition Vector.h:384
static bool is_na(stored_type x)
Definition Vector.h:253
void push_front__impl(const stored_type &object, traits::true_type)
Definition Vector.h:742
const_Proxy operator()(const size_t &i) const
Definition Vector.h:359
void push_front_name__impl(const stored_type &object, const std::string &name, traits::true_type)
Definition Vector.h:796
Vector(const Dimension &dims, const U &u)
Definition Vector.h:153
Vector(const T &siz, stored_type(*gen)(void), typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:114
static Vector create__dispatch(traits::false_type, const T &... t)
Definition Vector.h:1148
static Vector create__dispatch(traits::true_type, const T &... t)
Definition Vector.h:1156
iterator insert__impl(iterator position, const stored_type &object_, traits::true_type)
Definition Vector.h:855
bool containsElementNamed(const char *target) const
Definition Vector.h:598
static void create_dispatch_impl(iterator &it, const T &t, const TArgs &... args)
Definition Vector.h:1172
Proxy operator()(const size_t &i, const size_t &j)
Definition Vector.h:370
traits::r_vector_const_iterator< RTYPE, StoragePolicy >::type const_iterator
Definition Vector.h:47
iterator end()
Definition Vector.h:333
static void replace_element__dispatch(traits::true_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Definition Vector.h:537
static void replace_element(iterator it, SEXP names, R_xlen_t index, const U &u)
Definition Vector.h:526
Proxy operator[](R_xlen_t i)
Definition Vector.h:339
void fill__dispatch(traits::false_type, const U &u)
Definition Vector.h:1118
R_xlen_t length() const
Definition Vector.h:267
const_Proxy operator()(const size_t &i, const size_t &j) const
Definition Vector.h:373
Indexer operator[](const Range &range)
Definition Vector.h:559
R_xlen_t offset(const int &i, const int &j) const
Definition Vector.h:281
Vector(const int &size)
Definition Vector.h:129
iterator insert(iterator position, const T &object)
Definition Vector.h:491
Vector(const sugar::SingleLogicalResult< NA, T > &obj)
Definition Vector.h:177
const_iterator end() const
Definition Vector.h:335
NameProxy operator()(const std::string &name) const
Definition Vector.h:387
static void replace_element__dispatch__isArgument(traits::false_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Definition Vector.h:542
traits::r_vector_name_proxy< RTYPE, StoragePolicy >::type NameProxy
Definition Vector.h:44
void fill(const U &u)
Definition Vector.h:328
traits::r_vector_proxy< RTYPE, StoragePolicy >::type value_type
Definition Vector.h:45
const SubsetProxy< RTYPE, StoragePolicy, RHS_RTYPE, RHS_NA, RHS_T > operator[](const VectorBase< RHS_RTYPE, RHS_NA, RHS_T > &rhs) const
Definition Vector.h:407
static void replace_element_impl(iterator &it, Shield< SEXP > &names, int &index, const T &t, const TArgs &... args)
Definition Vector.h:1183
traits::r_vector_element_converter< RTYPE >::type converter_type
Definition Vector.h:49
Vector(T size, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:123
Vector(const T &siz, stored_type(*gen)(U1, U2), const U1 &u1, const U2 &u2, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:193
void push_front(const T &object, const std::string &name)
Definition Vector.h:484
Vector(const T &siz, stored_type(*gen)(U1), const U1 &u1, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:184
void push_front__impl(const stored_type &object, traits::false_type)
Definition Vector.h:769
void update(SEXP)
Definition Vector.h:521
static stored_type get_na()
Definition Vector.h:250
void import_sugar_expression(const Rcpp::VectorBase< RTYPE, NA, VEC > &other, traits::false_type)
Definition Vector.h:1079
static void replace_element_impl(iterator &it, Shield< SEXP > &names, int &index, const T &t)
Definition Vector.h:1178
NameProxy operator()(const std::string &name)
Definition Vector.h:380
void import_expression(const T &other, R_xlen_t n)
Definition Vector.h:1095
StoragePolicy< Vector > Storage
Definition Vector.h:39
const_iterator cbegin() const
Definition Vector.h:336
SubsetProxy< RTYPE, StoragePolicy, RHS_RTYPE, RHS_NA, RHS_T > operator[](const VectorBase< RHS_RTYPE, RHS_NA, RHS_T > &rhs)
Definition Vector.h:398
void push_back(const T &object)
Definition Vector.h:464
Vector(InputIterator first, InputIterator last, Func func, T n, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:233
Vector(const int &size, const stored_type &u)
Definition Vector.h:95
void push_front(const T &object)
Definition Vector.h:478
iterator begin()
Definition Vector.h:332
R_xlen_t offset(const R_xlen_t &i) const
Definition Vector.h:301
Proxy at(const size_t &i)
Definition Vector.h:363
void assign_object(const T &x, traits::true_type)
Definition Vector.h:1065
static void create_dispatch_impl(iterator &it, const T &t)
Definition Vector.h:1167
static void replace_element__dispatch(traits::false_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Definition Vector.h:532
Vector(InputIterator first, InputIterator last, Func func)
Definition Vector.h:226
const_Proxy at(const size_t &i) const
Definition Vector.h:366
void push_back__impl(const stored_type &object, traits::false_type)
Definition Vector.h:662
Vector(InputIterator first, InputIterator last)
Definition Vector.h:211
NameProxy operator[](const std::string &name)
Definition Vector.h:377
static Vector create()
Definition Vector.h:1134
Vector(const char *st)
Definition Vector.h:108
static void replace_element__dispatch__isArgument(traits::true_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Definition Vector.h:550
Vector & operator=(const Vector &rhs)
Definition Vector.h:68
Vector(const T &siz, stored_type(*gen)(U1, U2, U3), const U1 &u1, const U2 &u2, const U3 &u3, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:202
traits::r_vector_iterator< RTYPE, StoragePolicy >::type iterator
Definition Vector.h:46
Vector(const no_init_vector &obj)
Definition Vector.h:83
const_iterator cend() const
Definition Vector.h:337
traits::init_type< RTYPE >::type init_type
Definition Vector.h:48
void fill__dispatch(traits::true_type, const U &u)
Definition Vector.h:1128
std::enable_if< std::is_integral< T >::value &&!std::is_same< T, R_xlen_t >::value, Proxy >::type operator[](T i)
Definition Vector.h:350
Vector(InputIterator first, InputIterator last, T n, typename Rcpp::traits::enable_if< traits::is_arithmetic< T >::value, void >::type *=0)
Definition Vector.h:218
Vector(const Vector &other)
Definition Vector.h:64
iterator insert(int position, const T &object)
Definition Vector.h:498
Proxy operator()(const size_t &i)
Definition Vector.h:356
Vector(const VectorBase< RTYPE, NA, VEC > &other)
Definition Vector.h:163
iterator insert__impl(iterator position, const stored_type &object, traits::false_type)
Definition Vector.h:896
void push_back(const T &object, const std::string &name)
Definition Vector.h:471
traits::r_vector_const_proxy< RTYPE, StoragePolicy >::type const_Proxy
Definition Vector.h:43
SEXP eval() const
Definition Vector.h:1190
void fill_or_generate__impl(const T &gen, traits::true_type)
Definition Vector.h:1106
Vector(T value, typename Rcpp::traits::enable_if< traits::is_bool< T >::value &&RTYPE==LGLSXP, void >::type *=0)
Definition Vector.h:146
iterator erase(iterator position)
Definition Vector.h:508
iterator erase(iterator first, iterator last)
Definition Vector.h:517
traits::r_vector_proxy< RTYPE, StoragePolicy >::type Proxy
Definition Vector.h:42
R_xlen_t offset(const std::string &name) const
Definition Vector.h:309
iterator erase(int first, int last)
Definition Vector.h:512
void init()
Definition Vector.h:629
void assign_sugar_expression(const T &x)
Definition Vector.h:1050
void push_back_name__impl(const stored_type &object, const std::string &name, traits::false_type)
Definition Vector.h:714
void assign_object(const T &x, traits::false_type)
Definition Vector.h:1071
Vector & sort(bool decreasing=false)
Definition Vector.h:414
static target get(const T &input)
Definition converter.h:33
R_xlen_t get() const
Definition no_init.h:34
#define RCPP_DEBUG_2(fmt, M1, M2)
Definition debug.h:45
#define RCPP_DEBUG_1(fmt, MSG)
Definition debug.h:44
#define RCPP_DEBUG_4(fmt, M1, M2, M3, M4)
Definition debug.h:47
#define DEMANGLE(__TYPE__)
Definition exceptions.h:403
#define RCPP_GET_NAMES(x)
Definition macros.h:45
SEXP vector_from_string(const std::string &st)
storage_type< RTYPE >::type get_na()
integral_constant< bool, true > true_type
bool is_na(typename storage_type< RTYPE >::type)
Definition is_na.h:32
integral_constant< bool, false > false_type
Rcpp API.
Definition algo.h:28
std::ostream & operator<<(std::ostream &os, const Date d)
Definition Date.h:172
void NORET stop(const std::string &message)
Definition exceptions.h:119
sugar::Range< RTYPE, NA, T > range(const VectorBase< RTYPE, NA, T > &x)
Definition range.h:86
SEXP r_cast(SEXP x)
Definition r_cast.h:158
DottedPairProxyPolicy< Language_Impl >::const_DottedPairProxy const_Proxy
Definition Language.h:38
SEXP Rcpp_eval(SEXP expr, SEXP env)
Definition Rcpp_eval.h:54
RObject_Impl< PreserveStorage > RObject
Definition RObject.h:58
static Na_Proxy NA
Definition Na_Proxy.h:52
SEXP wrap(const Date &date)
Definition Date.h:38
SEXP get() const
storage_type< RTYPE >::type type
Definition init_type.h:29
r_vector_cache< RTYPE, StoragePolicy > type
Definition traits.h:105
const storage_type< RTYPE >::type * type
Definition proxy.h:254
const storage_type< RTYPE >::type & type
Definition proxy.h:233
::Rcpp::internal::element_converter< RTYPE > type
Definition converter.h:95
storage_type< RTYPE >::type * type
Definition proxy.h:250
::Rcpp::internal::simple_name_proxy< RTYPE, StoragePolicy > type
Definition proxy.h:199
storage_type< RTYPE >::type & type
Definition proxy.h:216
#define RCPP_LOOP_UNROLL(TARGET, SOURCE)
Definition unroll.h:47