diff --git a/inst/include/cpp11/complexes.hpp b/inst/include/cpp11/complexes.hpp index 5ca3585c..2fa41410 100644 --- a/inst/include/cpp11/complexes.hpp +++ b/inst/include/cpp11/complexes.hpp @@ -61,9 +61,9 @@ typedef r_vector complexes; namespace writable { template <> -inline void r_vector::set_elt( - SEXP x, R_xlen_t i, typename r_vector::underlying_type value) { - SET_COMPLEX_ELT(x, i, static_cast(value)); +inline void r_vector::set_elt(SEXP x, R_xlen_t i, + r_vector::underlying_type value) { + COMPLEX(x)[i] = static_cast(value); } typedef r_vector complexes; @@ -98,8 +98,11 @@ class r_vector::proxy { proxy(SEXP data, R_xlen_t index) : data_(data), index_(index), buf_(nullptr), is_altrep_(false) {} - proxy(SEXP data, R_xlen_t index, Rcomplex* buf, bool is_altrep) - : data_(data), index_(index), buf_(buf), is_altrep_(is_altrep) {} + proxy(SEXP data, R_xlen_t index, r_complex* buf, bool is_altrep) + : data_(data), + index_(index), + buf_(reinterpret_cast(buf)), + is_altrep_(is_altrep) {} operator r_complex() const { if (is_altrep_ && buf_ != nullptr) { diff --git a/inst/include/cpp11/r_complex.hpp b/inst/include/cpp11/r_complex.hpp index 5b2c76ad..19bcbc98 100644 --- a/inst/include/cpp11/r_complex.hpp +++ b/inst/include/cpp11/r_complex.hpp @@ -43,12 +43,10 @@ inline void writable::r_vector::push_back(r_complex value) { this->reserve(this->capacity_ == 0 ? 1 : this->capacity_ * 2); } - Rcomplex r_value = static_cast(value); - if (this->data_p_ != nullptr) { - this->data_p_[this->length_] = r_value; + this->data_p_[this->length_] = static_cast(value); } else { - this->set_elt(this->data_, this->length_, r_value); + set_elt(this->data_, this->length_, value); } ++this->length_; diff --git a/inst/include/cpp11/r_vector.hpp b/inst/include/cpp11/r_vector.hpp index 576f4fe6..1edf3233 100644 --- a/inst/include/cpp11/r_vector.hpp +++ b/inst/include/cpp11/r_vector.hpp @@ -237,6 +237,8 @@ class r_vector : public cpp11::r_vector { void push_back(T value); /// Implemented in `strings.hpp` void push_back(const named_arg& value); + // Implemented in `complexes.hpp` + void push_back(const std::complex& value); void pop_back(); void resize(R_xlen_t count);