@@ -56,6 +56,8 @@ class r_vector {
5656 typedef T* pointer;
5757 typedef T& reference;
5858
59+ using underlying_type = typename traits::get_underlying_type<T>::type;
60+
5961 r_vector () noexcept = default ;
6062
6163 r_vector (SEXP data);
@@ -173,7 +175,7 @@ class r_vector {
173175 void fill_buf (R_xlen_t pos);
174176
175177 R_xlen_t pos_;
176- std::array<T , 64 * 64 > buf_;
178+ std::array<underlying_type , 64 * 64 > buf_;
177179 R_xlen_t block_start_ = 0 ;
178180 R_xlen_t length_ = 0 ;
179181 };
@@ -193,10 +195,10 @@ class r_vector {
193195 SEXP data_ = R_NilValue;
194196 SEXP protect_ = R_NilValue;
195197 bool is_altrep_ = false ;
196- T * data_p_ = nullptr ;
198+ underlying_type * data_p_ = nullptr ;
197199 R_xlen_t length_ = 0 ;
198200
199- static T * get_p (bool is_altrep, SEXP data);
201+ static underlying_type * get_p (bool is_altrep, SEXP data);
200202
201203 static SEXP valid_type (SEXP data);
202204
@@ -216,6 +218,8 @@ class r_vector : public cpp11::r_vector<T> {
216218
217219 // These are necessary because type names are not directly accessible in
218220 // template inheritance
221+ using typename cpp11::r_vector<T>::underlying_type;
222+
219223 using cpp11::r_vector<T>::data_;
220224 using cpp11::r_vector<T>::data_p_;
221225 using cpp11::r_vector<T>::is_altrep_;
@@ -228,11 +232,11 @@ class r_vector : public cpp11::r_vector<T> {
228232 private:
229233 const SEXP data_;
230234 const R_xlen_t index_;
231- T * const p_;
235+ underlying_type * const p_;
232236 bool is_altrep_;
233237
234238 public:
235- proxy (SEXP data, const R_xlen_t index, T * const p, bool is_altrep);
239+ proxy (SEXP data, const R_xlen_t index, underlying_type * const p, bool is_altrep);
236240
237241 proxy& operator =(const T& rhs);
238242 proxy& operator +=(const T& rhs);
@@ -572,9 +576,9 @@ inline typename cpp11::r_vector<T>::const_iterator cpp11::r_vector<T>::find(
572576template <typename T>
573577inline T r_vector<T>::const_iterator::operator *() const {
574578 if (data_->is_altrep ()) {
575- return buf_[pos_ - block_start_];
579+ return static_cast <T>( buf_[pos_ - block_start_]) ;
576580 } else {
577- return data_->data_p_ [pos_];
581+ return static_cast <T>( data_->data_p_ [pos_]) ;
578582 }
579583}
580584
@@ -598,13 +602,17 @@ inline T r_vector<T>::operator[](size_type pos) const {
598602namespace writable {
599603
600604template <typename T>
601- r_vector<T>::proxy::proxy(SEXP data, const R_xlen_t index, T* const p, bool is_altrep)
605+ r_vector<T>::proxy::proxy(SEXP data, const R_xlen_t index,
606+ typename r_vector<T>::underlying_type* const p, bool is_altrep)
602607 : data_(data), index_(index), p_(p), is_altrep_(is_altrep) {}
603608
604609template <typename T>
605610inline typename r_vector<T>::proxy r_vector<T>::iterator::operator *() const {
606611 if (data_.is_altrep ()) {
607- return proxy (data_.data (), pos_, const_cast <T*>(&buf_[pos_ - block_start_]), true );
612+ return proxy (
613+ data_.data (), pos_,
614+ const_cast <typename r_vector<T>::underlying_type*>(&buf_[pos_ - block_start_]),
615+ true );
608616 } else {
609617 return proxy (data_.data (), pos_,
610618 data_.data_p_ != nullptr ? &data_.data_p_ [pos_] : nullptr , false );
0 commit comments