| 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 | } |