Rcpp Version 0.12.12
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 
337  inline Proxy operator[]( R_xlen_t i ){ return cache.ref(i) ; }
338  inline const_Proxy operator[]( R_xlen_t i ) const { return cache.ref(i) ; }
339 
340  inline Proxy operator()( const size_t& i) {
341  return cache.ref( offset(i) ) ;
342  }
343  inline const_Proxy operator()( const size_t& i) const {
344  return cache.ref( offset(i) ) ;
345  }
346 
347  inline Proxy at( const size_t& i) {
348  return cache.ref( offset(i) ) ;
349  }
350  inline const_Proxy at( const size_t& i) const {
351  return cache.ref( offset(i) ) ;
352  }
353 
354  inline Proxy operator()( const size_t& i, const size_t& j) {
355  return cache.ref( offset(i,j) ) ;
356  }
357  inline const_Proxy operator()( const size_t& i, const size_t& j) const {
358  return cache.ref( offset(i,j) ) ;
359  }
360 
361  inline NameProxy operator[]( const std::string& name ){
362  return NameProxy( *this, name ) ;
363  }
364  inline NameProxy operator()( const std::string& name ){
365  return NameProxy( *this, name ) ;
366  }
367 
368  inline NameProxy operator[]( const std::string& name ) const {
369  return NameProxy( const_cast<Vector&>(*this), name ) ;
370  }
371  inline NameProxy operator()( const std::string& name ) const {
372  return NameProxy( const_cast<Vector&>(*this), name ) ;
373  }
374 
375  inline operator RObject() const {
376  return RObject( Storage::get__() );
377  }
378 
379  // sugar subsetting requires dispatch on VectorBase
380  template <int RHS_RTYPE, bool RHS_NA, typename RHS_T>
384  *this,
385  rhs
386  );
387  }
388 
389  template <int RHS_RTYPE, bool RHS_NA, typename RHS_T>
393  const_cast< Vector<RTYPE, StoragePolicy>& >(*this),
394  rhs
395  );
396  }
397 
398  Vector& sort(bool decreasing = false) {
399  // sort() does not apply to List, RawVector or ExpressionVector.
400  //
401  // The function below does nothing for qualified Vector types,
402  // and is undefined for other types. Hence there will be a
403  // compiler error when sorting List, RawVector or ExpressionVector.
404  internal::Sort_is_not_allowed_for_this_type<RTYPE>::do_nothing();
405 
406  typename traits::storage_type<RTYPE>::type* start = internal::r_vector_start<RTYPE>( Storage::get__() );
407 
408  if (!decreasing) {
409  std::sort(
410  start,
411  start + size(),
412  internal::NAComparator<typename traits::storage_type<RTYPE>::type>()
413  );
414  } else {
415  std::sort(
416  start,
417  start + size(),
418  internal::NAComparatorGreater<typename traits::storage_type<RTYPE>::type>()
419  );
420  }
421 
422  return *this;
423  }
424 
425  template <typename InputIterator>
426  void assign( InputIterator first, InputIterator last){
427  /* FIXME: we can do better than this r_cast to avoid
428  allocating an unnecessary temporary object
429  */
430  Shield<SEXP> wrapped(wrap(first, last));
431  Shield<SEXP> casted(r_cast<RTYPE>(wrapped));
432  Storage::set__(casted) ;
433  }
434 
435  template <typename InputIterator>
436  static Vector import( InputIterator first, InputIterator last){
437  Vector v ;
438  v.assign( first , last ) ;
439  return v ;
440  }
441 
442  template <typename InputIterator, typename F>
443  static Vector import_transform( InputIterator first, InputIterator last, F f){
444  return Vector( first, last, f) ;
445  }
446 
447  template <typename T>
448  void push_back( const T& object){
451  ) ;
452  }
453 
454  template <typename T>
455  void push_back( const T& object, const std::string& name ){
458  ) ;
459  }
460 
461  template <typename T>
462  void push_front( const T& object){
465  }
466 
467  template <typename T>
468  void push_front( const T& object, const std::string& name){
471  }
472 
473 
474  template <typename T>
475  iterator insert( iterator position, const T& object){
476  return insert__impl( position, converter_type::get(object),
478  ) ;
479  }
480 
481  template <typename T>
482  iterator insert( int position, const T& object){
483  return insert__impl( cache.get() + position, converter_type::get(object),
485  );
486  }
487 
488  iterator erase( int position){
489  return erase_single__impl( cache.get() + position) ;
490  }
491 
492  iterator erase( iterator position){
493  return erase_single__impl( position ) ;
494  }
495 
496  iterator erase( int first, int last){
497  iterator start = cache.get() ;
498  return erase_range__impl( start + first, start + last ) ;
499  }
500 
501  iterator erase( iterator first, iterator last){
502  return erase_range__impl( first, last ) ;
503  }
504 
505  void update(SEXP){
506  cache.update(*this) ;
507  }
508 
509  template <typename U>
510  static void replace_element( iterator it, SEXP names, R_xlen_t index, const U& u){
512  it, names, index, u ) ;
513  }
514 
515  template <typename U>
516  static void replace_element__dispatch( traits::false_type, iterator it, SEXP names, R_xlen_t index, const U& u){
517  *it = converter_type::get(u);
518  }
519 
520  template <typename U>
521  static void replace_element__dispatch( traits::true_type, iterator it, SEXP names, R_xlen_t index, const U& u){
522  replace_element__dispatch__isArgument( typename traits::same_type<U,Argument>(), it, names, index, u ) ;
523  }
524 
525  template <typename U>
526  static void replace_element__dispatch__isArgument( traits::false_type, iterator it, SEXP names, R_xlen_t index, const U& u){
527  RCPP_DEBUG_2( " Vector::replace_element__dispatch<%s>(true, index= %d) ", DEMANGLE(U), index ) ;
528 
529  *it = converter_type::get(u.object ) ;
530  SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
531  }
532 
533  template <typename U>
534  static void replace_element__dispatch__isArgument( traits::true_type, iterator it, SEXP names, R_xlen_t index, const U& u){
535  RCPP_DEBUG_2( " Vector::replace_element__dispatch<%s>(true, index= %d) ", DEMANGLE(U), index ) ;
536 
537  *it = R_MissingArg ;
538  SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
539  }
540 
542 
543  inline Indexer operator[]( const Range& range ){
544  return Indexer( const_cast<Vector&>(*this), range );
545  }
546 
547  template <typename EXPR_VEC>
549  const EXPR_VEC& ref = rhs.get_ref() ;
550  iterator start = begin() ;
551  R_xlen_t n = size() ;
552  // TODO: maybe unroll this
553  stored_type tmp ;
554  for( R_xlen_t i=0; i<n; i++){
555  Proxy left = start[i] ;
556  if( ! traits::is_na<RTYPE>( left ) ){
557  tmp = ref[i] ;
558  left = traits::is_na<RTYPE>( tmp ) ? tmp : ( left + tmp ) ;
559  }
560  }
561  return *this ;
562  }
563 
564  template <typename EXPR_VEC>
566  const EXPR_VEC& ref = rhs.get_ref() ;
567  iterator start = begin() ;
568  R_xlen_t n = size() ;
569  stored_type tmp ;
570  for( R_xlen_t i=0; i<n; i++){
571  if( ! traits::is_na<RTYPE>(start[i]) ){
572  start[i] += ref[i] ;
573  }
574  }
575  return *this ;
576 
577  }
578 
582  bool containsElementNamed( const char* target ) const {
583  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
584  if( Rf_isNull(names) ) return false ;
585  R_xlen_t n = Rf_xlength(names) ;
586  for( R_xlen_t i=0; i<n; i++){
587  if( !strcmp( target, CHAR(STRING_ELT(names, i)) ) )
588  return true ;
589  }
590  return false ;
591  }
592 
593  int findName(const std::string& name) const {
594  SEXP names = RCPP_GET_NAMES(Storage::get__());
595  if (Rf_isNull(names)) stop("'names' attribute is null");
596  R_xlen_t n = Rf_xlength(names);
597  for (R_xlen_t i=0; i < n; ++i) {
598  if (strcmp(name.c_str(), CHAR(STRING_ELT(names, i))) == 0) {
599  return i;
600  }
601  }
602  std::stringstream ss;
603  ss << "no name '" << name << "' found";
604  stop(ss.str());
605  return -1;
606  }
607 
608 protected:
609  inline int* dims() const {
610  if( !::Rf_isMatrix(Storage::get__()) ) throw not_a_matrix() ;
611  return INTEGER( ::Rf_getAttrib( Storage::get__(), R_DimSymbol ) ) ;
612  }
613  void init(){
614  RCPP_DEBUG_2( "VECTOR<%d>::init( SEXP = <%p> )", RTYPE, Storage::get__() )
615  internal::r_init_vector<RTYPE>(Storage::get__()) ;
616  }
617 
618 private:
619 
620  void push_back__impl(const stored_type& object, traits::true_type ) {
621  Shield<SEXP> object_sexp( object ) ;
622  R_xlen_t n = size() ;
623  Vector target( n + 1 ) ;
624  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
625  iterator target_it( target.begin() ) ;
626  iterator it(begin()) ;
627  iterator this_end(end());
628  if( Rf_isNull(names) ){
629  for( ; it < this_end; ++it, ++target_it ){
630  *target_it = *it ;
631  }
632  } else {
633  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) ) ;
634  int i = 0 ;
635  for( ; it < this_end; ++it, ++target_it, i++ ){
636  *target_it = *it ;
637  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
638  }
639  SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
640  target.attr("names") = newnames ;
641  }
642  *target_it = object_sexp;
643  Storage::set__( target.get__() ) ;
644  }
645 
646  void push_back__impl(const stored_type& object, traits::false_type ) {
647  R_xlen_t n = size() ;
648  Vector target( n + 1 ) ;
649  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
650  iterator target_it( target.begin() ) ;
651  iterator it(begin()) ;
652  iterator this_end(end());
653  if( Rf_isNull(names) ){
654  for( ; it < this_end; ++it, ++target_it ){
655  *target_it = *it ;
656  }
657  } else {
658  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) ) ;
659  int i = 0 ;
660  for( ; it < this_end; ++it, ++target_it, i++ ){
661  *target_it = *it ;
662  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
663  }
664  SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
665  target.attr("names") = newnames ;
666  }
667  *target_it = object;
668  Storage::set__( target.get__() ) ;
669  }
670 
671  void push_back_name__impl(const stored_type& object, const std::string& name, traits::true_type ) {
672  Shield<SEXP> object_sexp( object ) ;
673  R_xlen_t n = size() ;
674  Vector target( n + 1 ) ;
675  iterator target_it( target.begin() ) ;
676  iterator it(begin()) ;
677  iterator this_end(end());
678  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
679  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
680  int i=0;
681  if( Rf_isNull(names) ){
682  for( ; it < this_end; ++it, ++target_it,i++ ){
683  *target_it = *it ;
684  SET_STRING_ELT( newnames, i , R_BlankString );
685  }
686  } else {
687  for( ; it < this_end; ++it, ++target_it, i++ ){
688  *target_it = *it ;
689  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
690  }
691  }
692  SET_STRING_ELT( newnames, i, Rf_mkChar( name.c_str() ) );
693  target.attr("names") = newnames ;
694 
695  *target_it = object_sexp;
696  Storage::set__( target.get__() ) ;
697  }
698  void push_back_name__impl(const stored_type& object, const std::string& name, traits::false_type ) {
699  R_xlen_t n = size() ;
700  Vector target( n + 1 ) ;
701  iterator target_it( target.begin() ) ;
702  iterator it(begin()) ;
703  iterator this_end(end());
704  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
705  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
706  int i=0;
707  if( Rf_isNull(names) ){
708  Shield<SEXP> dummy( Rf_mkChar("") );
709  for( ; it < this_end; ++it, ++target_it,i++ ){
710  *target_it = *it ;
711  SET_STRING_ELT( newnames, i , dummy );
712  }
713  } else {
714  for( ; it < this_end; ++it, ++target_it, i++ ){
715  *target_it = *it ;
716  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
717  }
718  }
719  SET_STRING_ELT( newnames, i, Rf_mkChar( name.c_str() ) );
720  target.attr("names") = newnames ;
721 
722  *target_it = object;
723  Storage::set__( target.get__() ) ;
724  }
725 
726  void push_front__impl(const stored_type& object, traits::true_type ) {
727  Shield<SEXP> object_sexp( object ) ;
728  R_xlen_t n = size() ;
729  Vector target( n+1);
730  iterator target_it(target.begin());
731  iterator it(begin());
732  iterator this_end(end());
733  *target_it = object_sexp ;
734  ++target_it ;
735  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
736  if( Rf_isNull(names) ){
737  for( ; it<this_end; ++it, ++target_it){
738  *target_it = *it ;
739  }
740  } else{
741  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) );
742  int i=1 ;
743  SET_STRING_ELT( newnames, 0, Rf_mkChar("") ) ;
744  for( ; it<this_end; ++it, ++target_it, i++){
745  *target_it = *it ;
746  SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
747  }
748  target.attr("names") = newnames ;
749  }
750  Storage::set__( target.get__() ) ;
751 
752  }
753  void push_front__impl(const stored_type& object, traits::false_type ) {
754  R_xlen_t n = size() ;
755  Vector target( n+1);
756  iterator target_it(target.begin());
757  iterator it(begin());
758  iterator this_end(end());
759  *target_it = object ;
760  ++target_it ;
761  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
762  if( Rf_isNull(names) ){
763  for( ; it<this_end; ++it, ++target_it){
764  *target_it = *it ;
765  }
766  } else{
767  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1) );
768  int i=1 ;
769  SET_STRING_ELT( newnames, 0, Rf_mkChar("") ) ;
770  for( ; it<this_end; ++it, ++target_it, i++){
771  *target_it = *it ;
772  SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
773  }
774  target.attr("names") = newnames ;
775  }
776  Storage::set__( target.get__() ) ;
777 
778  }
779 
780  void push_front_name__impl(const stored_type& object, const std::string& name, traits::true_type ) {
781  Shield<SEXP> object_sexp(object) ;
782  R_xlen_t n = size() ;
783  Vector target( n + 1 ) ;
784  iterator target_it( target.begin() ) ;
785  iterator it(begin()) ;
786  iterator this_end(end());
787  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
788  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
789  int i=1;
790  SET_STRING_ELT( newnames, 0, Rf_mkChar( name.c_str() ) );
791  *target_it = object_sexp;
792  ++target_it ;
793 
794  if( Rf_isNull(names) ){
795  for( ; it < this_end; ++it, ++target_it,i++ ){
796  *target_it = *it ;
797  SET_STRING_ELT( newnames, i , R_BlankString );
798  }
799  } else {
800  for( ; it < this_end; ++it, ++target_it, i++ ){
801  *target_it = *it ;
802  SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
803  }
804  }
805  target.attr("names") = newnames ;
806  Storage::set__( target.get__() ) ;
807 
808  }
809  void push_front_name__impl(const stored_type& object, const std::string& name, traits::false_type ) {
810  R_xlen_t n = size() ;
811  Vector target( n + 1 ) ;
812  iterator target_it( target.begin() ) ;
813  iterator it(begin()) ;
814  iterator this_end(end());
815  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
816  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n+1 ) ) ;
817  int i=1;
818  SET_STRING_ELT( newnames, 0, Rf_mkChar( name.c_str() ) );
819  *target_it = object;
820  ++target_it ;
821 
822  if( Rf_isNull(names) ){
823  for( ; it < this_end; ++it, ++target_it,i++ ){
824  *target_it = *it ;
825  SET_STRING_ELT( newnames, i , R_BlankString );
826  }
827  } else {
828  for( ; it < this_end; ++it, ++target_it, i++ ){
829  *target_it = *it ;
830  SET_STRING_ELT( newnames, i, STRING_ELT(names, i-1 ) ) ;
831  }
832  }
833  target.attr("names") = newnames ;
834 
835  Storage::set__( target.get__() ) ;
836 
837  }
838 
839  iterator insert__impl( iterator position, const stored_type& object_, traits::true_type ) {
840  Shield<SEXP> object( object_ ) ;
841  R_xlen_t n = size() ;
842  Vector target( n+1 ) ;
843  iterator target_it = target.begin();
844  iterator it = begin() ;
845  iterator this_end = end() ;
846  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
847  iterator result ;
848  if( Rf_isNull(names) ){
849  for( ; it < position; ++it, ++target_it){
850  *target_it = *it ;
851  }
852  result = target_it;
853  *target_it = object ;
854  ++target_it ;
855  for( ; it < this_end; ++it, ++target_it ){
856  *target_it = *it ;
857  }
858  } else{
859  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1 ) ) ;
860  int i=0;
861  for( ; it < position; ++it, ++target_it, i++){
862  *target_it = *it ;
863  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
864  }
865  result = target_it;
866  *target_it = object ;
867  SET_STRING_ELT( newnames, i, ::Rf_mkChar("") ) ;
868  i++ ;
869  ++target_it ;
870  for( ; it < this_end; ++it, ++target_it, i++ ){
871  *target_it = *it ;
872  SET_STRING_ELT( newnames, i, STRING_ELT(names, i - 1) ) ;
873  }
874  target.attr( "names" ) = newnames ;
875  }
876  Storage::set__( target.get__() ) ;
877  return result ;
878  }
879 
880  iterator insert__impl( iterator position, const stored_type& object, traits::false_type ) {
881  R_xlen_t n = size() ;
882  Vector target( n+1 ) ;
883  iterator target_it = target.begin();
884  iterator it = begin() ;
885  iterator this_end = end() ;
886  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
887  iterator result ;
888  if( Rf_isNull(names) ){
889  for( ; it < position; ++it, ++target_it){
890  *target_it = *it ;
891  }
892  result = target_it;
893  *target_it = object ;
894  ++target_it ;
895  for( ; it < this_end; ++it, ++target_it ){
896  *target_it = *it ;
897  }
898  } else{
899  Shield<SEXP> newnames( ::Rf_allocVector( STRSXP, n + 1 ) ) ;
900  int i=0;
901  for( ; it < position; ++it, ++target_it, i++){
902  *target_it = *it ;
903  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
904  }
905  result = target_it;
906  *target_it = object ;
907  SET_STRING_ELT( newnames, i, ::Rf_mkChar("") ) ;
908  i++ ;
909  ++target_it ;
910  for( ; it < this_end; ++it, ++target_it, i++ ){
911  *target_it = *it ;
912  SET_STRING_ELT( newnames, i, STRING_ELT(names, i - 1) ) ;
913  }
914  target.attr( "names" ) = newnames ;
915  }
916  Storage::set__( target.get__() ) ;
917  return result ;
918  }
919 
920  iterator erase_single__impl( iterator position ) {
921  if( position < begin() || position > end() ) {
922  R_xlen_t requested_loc;
923  R_xlen_t available_locs = std::distance(begin(), end());
924 
925  if(position > end()){
926  requested_loc = std::distance(position, begin());
927  } else {
928  // This will be a negative number
929  requested_loc = std::distance(begin(), position);
930  }
931  const char* fmt = "Iterator index is out of bounds: "
932  "[iterator index=%i; iterator extent=%i]";
933  throw index_out_of_bounds(fmt, requested_loc, available_locs ) ;
934  }
935 
936  R_xlen_t n = size() ;
937  Vector target( n - 1 ) ;
938  iterator target_it(target.begin()) ;
939  iterator it(begin()) ;
940  iterator this_end(end()) ;
941  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
942  if( Rf_isNull(names) ){
943  int i=0;
944  for( ; it < position; ++it, ++target_it, i++){
945  *target_it = *it;
946  }
947  ++it ;
948  for( ; it < this_end ; ++it, ++target_it){
949  *target_it = *it;
950  }
951  Storage::set__( target.get__() ) ;
952  return begin()+i ;
953  } else {
954  Shield<SEXP> newnames(::Rf_allocVector( STRSXP, n-1 ));
955  int i= 0 ;
956  for( ; it < position; ++it, ++target_it,i++){
957  *target_it = *it;
958  SET_STRING_ELT( newnames, i , STRING_ELT(names,i) ) ;
959  }
960  int result=i ;
961  ++it ;
962  i++ ;
963  for( ; it < this_end ; ++it, ++target_it, i++){
964  *target_it = *it;
965  SET_STRING_ELT( newnames, i-1, STRING_ELT(names,i) ) ;
966  }
967  target.attr( "names" ) = newnames ;
968  Storage::set__( target.get__() ) ;
969  return begin()+result ;
970  }
971  }
972 
973  iterator erase_range__impl( iterator first, iterator last ) {
974  if( first > last ) throw std::range_error("invalid range") ;
975  if( last > end() || first < begin() ) {
976  R_xlen_t requested_loc;
977  R_xlen_t available_locs = std::distance(begin(), end());
978  std::string iter_problem;
979 
980  if(last > end()){
981  requested_loc = std::distance(last, begin());
982  iter_problem = "last";
983  } else {
984  // This will be a negative number
985  requested_loc = std::distance(begin(), first);
986  iter_problem = "first";
987  }
988  const char* fmt = "Iterator index is out of bounds: "
989  "[iterator=%s; index=%i; extent=%i]";
990  throw index_out_of_bounds(fmt, iter_problem,
991  requested_loc, available_locs ) ;
992  }
993 
994  iterator it = begin() ;
995  iterator this_end = end() ;
996  R_xlen_t nremoved = std::distance(first,last) ;
997  R_xlen_t target_size = size() - nremoved ;
998  Vector target( target_size ) ;
999  iterator target_it = target.begin() ;
1000 
1001  SEXP names = RCPP_GET_NAMES(Storage::get__()) ;
1002  int result = 0;
1003  if( Rf_isNull(names) ){
1004  int i=0;
1005  for( ; it < first; ++it, ++target_it, i++ ){
1006  *target_it = *it ;
1007  }
1008  result = i;
1009  for( it = last ; it < this_end; ++it, ++target_it ){
1010  *target_it = *it ;
1011  }
1012  } else{
1013  Shield<SEXP> newnames( ::Rf_allocVector(STRSXP, target_size) ) ;
1014  int i= 0 ;
1015  for( ; it < first; ++it, ++target_it, i++ ){
1016  *target_it = *it ;
1017  SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) );
1018  }
1019  result = i;
1020  for( it = last ; it < this_end; ++it, ++target_it, i++ ){
1021  *target_it = *it ;
1022  SET_STRING_ELT( newnames, i, STRING_ELT(names, i + nremoved ) );
1023  }
1024  target.attr("names" ) = newnames ;
1025  }
1026  Storage::set__( target.get__() ) ;
1027 
1028  return begin() + result;
1029 
1030  }
1031 
1032  template <typename T>
1033  inline void assign_sugar_expression( const T& x ) {
1034  R_xlen_t n = size() ;
1035  if( n == x.size() ){
1036  // just copy the data
1037  import_expression<T>(x, n ) ;
1038  } else{
1039  // different size, so we change the memory
1040  Shield<SEXP> wrapped(wrap(x));
1041  Shield<SEXP> casted(r_cast<RTYPE>(wrapped));
1042  Storage::set__(casted);
1043  }
1044  }
1045 
1046  // sugar
1047  template <typename T>
1048  inline void assign_object( const T& x, traits::true_type ) {
1049  assign_sugar_expression( x.get_ref() ) ;
1050  }
1051 
1052  // anything else
1053  template <typename T>
1054  inline void assign_object( const T& x, traits::false_type ) {
1055  Shield<SEXP> wrapped(wrap(x));
1056  Shield<SEXP> casted(r_cast<RTYPE>(wrapped));
1057  Storage::set__(casted);
1058  }
1059 
1060  // we are importing a real sugar expression, i.e. not a vector
1061  template <bool NA, typename VEC>
1063  RCPP_DEBUG_4( "Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, false_type )", RTYPE, NA, RTYPE, DEMANGLE(VEC) ) ;
1064  R_xlen_t n = other.size() ;
1065  Storage::set__( Rf_allocVector( RTYPE, n ) ) ;
1066  import_expression<VEC>( other.get_ref() , n ) ;
1067  }
1068 
1069  // we are importing a sugar expression that actually is a vector
1070  template <bool NA, typename VEC>
1072  RCPP_DEBUG_4( "Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, true_type )", RTYPE, NA, RTYPE, DEMANGLE(VEC) ) ;
1073  Storage::set__( other.get_ref() ) ;
1074  }
1075 
1076 
1077  template <typename T>
1078  inline void import_expression( const T& other, R_xlen_t n ) {
1079  iterator start = begin() ;
1080  RCPP_LOOP_UNROLL(start,other)
1081  }
1082 
1083  template <typename T>
1084  inline void fill_or_generate( const T& t) {
1086  }
1087 
1088  template <typename T>
1089  inline void fill_or_generate__impl( const T& gen, traits::true_type) {
1090  iterator first = begin() ;
1091  iterator last = end() ;
1092  while( first != last ) *first++ = gen() ;
1093  }
1094 
1095  template <typename T>
1096  inline void fill_or_generate__impl( const T& t, traits::false_type) {
1097  fill(t) ;
1098  }
1099 
1100  template <typename U>
1102  // when this is not trivial, this is SEXP
1103  Shield<SEXP> elem( converter_type::get( u ) );
1104  iterator it(begin());
1105  for( R_xlen_t i=0; i<size() ; i++, ++it){
1106  *it = ::Rf_duplicate( elem ) ;
1107  }
1108  }
1109 
1110  template <typename U>
1111  void fill__dispatch( traits::true_type, const U& u){
1112  std::fill( begin(), end(), converter_type::get( u ) ) ;
1113  }
1114 
1115 public:
1116 
1117  static Vector create(){
1118  return Vector( 0 ) ;
1119  }
1120 
1121  #include <Rcpp/generated/Vector__create.h>
1122 
1123 public:
1124 
1125  inline SEXP eval() const {
1126  return Rcpp_eval( Storage::get__(), R_GlobalEnv ) ;
1127  }
1128 
1129  inline SEXP eval(SEXP env) const {
1130  return Rcpp_eval( Storage::get__(), env );
1131  }
1132 
1133 
1134 } ; /* Vector */
1135 
1136 template <int RTYPE, template <class> class StoragePolicy >
1137 inline std::ostream &operator<<(std::ostream & s, const Vector<RTYPE, StoragePolicy> & rhs) {
1138  typedef Vector<RTYPE, StoragePolicy> VECTOR;
1139 
1140  typename VECTOR::iterator i = const_cast<VECTOR &>(rhs).begin();
1141  typename VECTOR::iterator iend = const_cast<VECTOR &>(rhs).end();
1142 
1143  if (i != iend) {
1144  s << (*i);
1145  ++i;
1146 
1147  for ( ; i != iend; ++i) {
1148  s << " " << (*i);
1149  }
1150  }
1151 
1152  return s;
1153 }
1154 
1155 template<template <class> class StoragePolicy >
1156 inline std::ostream &operator<<(std::ostream & s, const Vector<STRSXP, StoragePolicy> & rhs) {
1157  typedef Vector<STRSXP, StoragePolicy> VECTOR;
1158 
1159  typename VECTOR::iterator i = const_cast<VECTOR &>(rhs).begin();
1160  typename VECTOR::iterator iend = const_cast<VECTOR &>(rhs).end();
1161 
1162  if (i != iend) {
1163  s << "\"" << (*i) << "\"";
1164  ++i;
1165 
1166  for ( ; i != iend; ++i) {
1167  s << " \"" << (*i) << "\"";
1168  }
1169  }
1170 
1171  return s;
1172 }
1173 
1174 }
1175 
1176 #endif
Vector(const Dimension &dims)
Definition: Vector.h:133
Proxy operator()(const size_t &i)
Definition: Vector.h:340
Proxy operator()(const size_t &i, const size_t &j)
Definition: Vector.h:354
void fill_or_generate__impl(const T &gen, traits::true_type)
Definition: Vector.h:1089
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:492
iterator insert(int position, const T &object)
Definition: Vector.h:482
Vector & operator+=(const VectorBase< RTYPE, false, EXPR_VEC > &rhs)
Definition: Vector.h:565
Proxy at(const size_t &i)
Definition: Vector.h:347
const_Proxy operator()(const size_t &i, const size_t &j) const
Definition: Vector.h:357
void init()
Definition: Vector.h:613
static bool is_na(stored_type x)
Definition: Vector.h:253
traits::r_vector_const_iterator< RTYPE >::type const_iterator
Definition: Vector.h:48
R_xlen_t size() const
Definition: VectorBase.h:49
int * dims() const
Definition: Vector.h:609
SEXP get() const
Definition: GenericProxy.h:25
Vector & operator=(const Vector &rhs)
Definition: Vector.h:69
R_xlen_t length() const
Definition: Vector.h:267
VECTOR & get_ref()
Definition: VectorBase.h:37
R_xlen_t prod() const
Definition: Dimension.h:59
traits::r_vector_cache_type< RTYPE, StoragePolicy >::type cache
Definition: Vector.h:42
Vector & sort(bool decreasing=false)
Definition: Vector.h:398
#define RCPP_LOOP_UNROLL(TARGET, SOURCE)
Definition: unroll.h:47
void import_expression(const T &other, R_xlen_t n)
Definition: Vector.h:1078
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:671
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:510
iterator erase(iterator first, iterator last)
Definition: Vector.h:501
static void replace_element__dispatch(traits::false_type, iterator it, SEXP names, R_xlen_t index, const U &u)
Definition: Vector.h:516
void push_front(const T &object, const std::string &name)
Definition: Vector.h:468
Vector(const std::string &st)
Definition: Vector.h:101
#define DEMANGLE(__TYPE__)
Definition: exceptions.h:315
traits::r_vector_iterator< RTYPE >::type iterator
Definition: Vector.h:47
void assign_object(const T &x, traits::false_type)
Definition: Vector.h:1054
Vector & operator=(const T &x)
Definition: Vector.h:245
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:1084
bool containsElementNamed(const char *target) const
Definition: Vector.h:582
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:526
const storage_type< RTYPE >::type & type
Definition: proxy.h:225
const_Proxy operator()(const size_t &i) const
Definition: Vector.h:343
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:780
void assign(InputIterator first, InputIterator last)
Definition: Vector.h:426
iterator erase(int position)
Definition: Vector.h:488
void fill__dispatch(traits::false_type, const U &u)
Definition: Vector.h:1101
iterator erase_range__impl(iterator first, iterator last)
Definition: Vector.h:973
void push_front__impl(const stored_type &object, traits::false_type)
Definition: Vector.h:753
SEXP eval(SEXP env) const
Definition: Vector.h:1129
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:443
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:534
void import_sugar_expression(const Rcpp::VectorBase< RTYPE, NA, VEC > &other, traits::false_type)
Definition: Vector.h:1062
SEXP Rcpp_eval(SEXP expr, SEXP env)
Definition: Rcpp_eval.h:25
Vector(InputIterator first, InputIterator last)
Definition: Vector.h:209
int size() const
Definition: Dimension.h:56
void update(SEXP)
Definition: Vector.h:505
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:1033
SEXP eval() const
Definition: Vector.h:1125
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:521
storage_type< RTYPE >::type & type
Definition: proxy.h:211
iterator insert(iterator position, const T &object)
Definition: Vector.h:475
const_Proxy at(const size_t &i) const
Definition: Vector.h:350
traits::storage_type< RTYPE >::type stored_type
Definition: Vector.h:51
R_xlen_t size() const
Definition: Vector.h:274
NameProxy operator()(const std::string &name) const
Definition: Vector.h:371
void push_back(const T &object)
Definition: Vector.h:448
R_xlen_t offset(const int &i, const int &j) const
Definition: Vector.h:281
iterator insert__impl(iterator position, const stored_type &object, traits::false_type)
Definition: Vector.h:880
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:1117
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:698
const SubsetProxy< RTYPE, StoragePolicy, RHS_RTYPE, RHS_NA, RHS_T > operator[](const VectorBase< RHS_RTYPE, RHS_NA, RHS_T > &rhs) const
Definition: Vector.h:391
R_xlen_t offset(const std::string &name) const
Definition: Vector.h:309
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
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:543
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:462
void push_back__impl(const stored_type &object, traits::true_type)
Definition: Vector.h:620
#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:1096
void assign_object(const T &x, traits::true_type)
Definition: Vector.h:1048
traits::r_vector_proxy< RTYPE >::type Proxy
Definition: Vector.h:43
SEXP wrap(const Date &date)
Definition: Date.h:38
void fill__dispatch(traits::true_type, const U &u)
Definition: Vector.h:1111
Vector(const Dimension &dims, const U &u)
Definition: Vector.h:152
const_iterator end() const
Definition: Vector.h:335
void NORET stop(const char *fmt, Args &&...args)
Definition: exceptions.h:51
iterator erase_single__impl(iterator position)
Definition: Vector.h:920
int findName(const std::string &name) const
Definition: Vector.h:593
const_iterator get_const() const
Definition: traits.h:43
RObject_Impl< PreserveStorage > RObject
Definition: RObject.h:56
Vector(const VectorBase< RTYPE, NA, VEC > &other)
Definition: Vector.h:162
void push_back(const T &object, const std::string &name)
Definition: Vector.h:455
iterator get() const
Definition: traits.h:42
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:337
SubsetProxy< RTYPE, StoragePolicy, RHS_RTYPE, RHS_NA, RHS_T > operator[](const VectorBase< RHS_RTYPE, RHS_NA, RHS_T > &rhs)
Definition: Vector.h:382
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:1071
internal::RangeIndexer< RTYPE, true, Vector > Indexer
Definition: Vector.h:541
void push_front__impl(const stored_type &object, traits::true_type)
Definition: Vector.h:726
#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
const_iterator begin() const
Definition: Vector.h:334
void push_front_name__impl(const stored_type &object, const std::string &name, traits::false_type)
Definition: Vector.h:809
void push_back__impl(const stored_type &object, traits::false_type)
Definition: Vector.h:646
NameProxy operator()(const std::string &name)
Definition: Vector.h:364
NameProxy operator[](const std::string &name) const
Definition: Vector.h:368
Vector & operator+=(const VectorBase< RTYPE, true, EXPR_VEC > &rhs)
Definition: Vector.h:548
storage_type< RTYPE >::type * type
Definition: proxy.h:239
NameProxy operator[](const std::string &name)
Definition: Vector.h:361
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:839
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:496
const_Proxy operator[](R_xlen_t i) const
Definition: Vector.h:338
sugar::Range< RTYPE, NA, T > range(const VectorBase< RTYPE, NA, T > &x)
Definition: range.h:86
R_xlen_t get() const
Definition: no_init.h:34