| 919 | } |
| 920 | |
| 921 | iterator erase_single__impl( iterator position ) { |
| 922 | if( position < begin() || position > end() ) { |
| 923 | R_xlen_t requested_loc; |
| 924 | R_xlen_t available_locs = std::distance(begin(), end()); |
| 925 | |
| 926 | if(position > end()){ |
| 927 | requested_loc = std::distance(position, begin()); |
| 928 | } else { |
| 929 | // This will be a negative number |
| 930 | requested_loc = std::distance(begin(), position); |
| 931 | } |
| 932 | const char* fmt = "Iterator index is out of bounds: " |
| 933 | "[iterator index=%i; iterator extent=%i]"; |
| 934 | throw index_out_of_bounds(fmt, requested_loc, available_locs ) ; |
| 935 | } |
| 936 | |
| 937 | R_xlen_t n = size() ; |
| 938 | |
| 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") ; |