| 47 | template <typename CLASS> |
| 48 | template <typename T> |
| 49 | void DottedPairImpl<CLASS>::insert( const size_t& index, const T& object) { |
| 50 | CLASS& ref = static_cast<CLASS&>(*this) ; |
| 51 | if( index == 0 ) { |
| 52 | push_front( object ) ; |
| 53 | } else { |
| 54 | if( ref.isNULL( ) ) { |
| 55 | throw index_out_of_bounds("Object being inserted into Dotted Pair is null."); |
| 56 | } |
| 57 | |
| 58 | if( static_cast<R_xlen_t>(index) > ::Rf_xlength(ref.get__()) ) { |
| 59 | const char* fmt = "Dotted Pair index is out of bounds: " |
| 60 | "[index=%i; extent=%i]."; |
| 61 | |
| 62 | throw index_out_of_bounds(fmt, |
| 63 | static_cast<R_xlen_t>(index), |
| 64 | ::Rf_xlength(ref.get__()) ) ; |
| 65 | } |
| 66 | |
| 67 | size_t i=1; |
| 68 | SEXP x = ref.get__() ; |
| 69 | while( i < index ){ |
| 70 | x = CDR(x) ; |
| 71 | i++; |
| 72 | } |
| 73 | Shield<SEXP> tail( grow( object, CDR(x) ) ); |
| 74 | SETCDR( x, tail ) ; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | template <typename CLASS> |
| 79 | template <typename T> |