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