@@ -55,6 +55,7 @@ class r_vector {
5555 typedef T value_type;
5656 typedef T* pointer;
5757 typedef T& reference;
58+ using underlying_type = typename traits::get_underlying_type<T>::type;
5859
5960 r_vector () noexcept = default ;
6061
@@ -173,7 +174,7 @@ class r_vector {
173174 void fill_buf (R_xlen_t pos);
174175
175176 R_xlen_t pos_;
176- std::array<T , 64 * 64 > buf_;
177+ std::array<underlying_type , 64 * 64 > buf_;
177178 R_xlen_t block_start_ = 0 ;
178179 R_xlen_t length_ = 0 ;
179180 };
@@ -193,10 +194,10 @@ class r_vector {
193194 SEXP data_ = R_NilValue;
194195 SEXP protect_ = R_NilValue;
195196 bool is_altrep_ = false ;
196- T * data_p_ = nullptr ;
197+ underlying_type * data_p_ = nullptr ;
197198 R_xlen_t length_ = 0 ;
198199
199- static T * get_p (bool is_altrep, SEXP data);
200+ static underlying_type * get_p (bool is_altrep, SEXP data);
200201
201202 static SEXP valid_type (SEXP data);
202203
@@ -216,6 +217,8 @@ class r_vector : public cpp11::r_vector<T> {
216217
217218 // These are necessary because type names are not directly accessible in
218219 // template inheritance
220+ using typename cpp11::r_vector<T>::underlying_type;
221+
219222 using cpp11::r_vector<T>::data_;
220223 using cpp11::r_vector<T>::data_p_;
221224 using cpp11::r_vector<T>::is_altrep_;
@@ -228,11 +231,11 @@ class r_vector : public cpp11::r_vector<T> {
228231 private:
229232 const SEXP data_;
230233 const R_xlen_t index_;
231- T * const p_;
234+ underlying_type * const p_;
232235 bool is_altrep_;
233236
234237 public:
235- proxy (SEXP data, const R_xlen_t index, T * const p, bool is_altrep);
238+ proxy (SEXP data, const R_xlen_t index, underlying_type * const p, bool is_altrep);
236239
237240 proxy& operator =(const T& rhs);
238241 proxy& operator +=(const T& rhs);
@@ -572,9 +575,9 @@ inline typename cpp11::r_vector<T>::const_iterator cpp11::r_vector<T>::find(
572575template <typename T>
573576inline T r_vector<T>::const_iterator::operator *() const {
574577 if (data_->is_altrep ()) {
575- return buf_[pos_ - block_start_];
578+ return static_cast <T>( buf_[pos_ - block_start_]) ;
576579 } else {
577- return data_->data_p_ [pos_];
580+ return static_cast <T>( data_->data_p_ [pos_]) ;
578581 }
579582}
580583
@@ -598,13 +601,17 @@ inline T r_vector<T>::operator[](size_type pos) const {
598601namespace writable {
599602
600603template <typename T>
601- r_vector<T>::proxy::proxy(SEXP data, const R_xlen_t index, T* const p, bool is_altrep)
604+ r_vector<T>::proxy::proxy(SEXP data, const R_xlen_t index,
605+ typename r_vector<T>::underlying_type* const p, bool is_altrep)
602606 : data_(data), index_(index), p_(p), is_altrep_(is_altrep) {}
603607
604608template <typename T>
605609inline typename r_vector<T>::proxy r_vector<T>::iterator::operator *() const {
606610 if (data_.is_altrep ()) {
607- return proxy (data_.data (), pos_, const_cast <T*>(&buf_[pos_ - block_start_]), true );
611+ return proxy (
612+ data_.data (), pos_,
613+ const_cast <typename r_vector<T>::underlying_type*>(&buf_[pos_ - block_start_]),
614+ true );
608615 } else {
609616 return proxy (data_.data (), pos_,
610617 data_.data_p_ != nullptr ? &data_.data_p_ [pos_] : nullptr , false );
0 commit comments