Skip to content

Commit 49ee179

Browse files
committed
trying to get push_back for cplx to work :\
1 parent 8e044f6 commit 49ee179

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

inst/include/cpp11/complexes.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ typedef r_vector<r_complex> complexes;
6161
namespace writable {
6262

6363
template <>
64-
inline void r_vector<r_complex>::set_elt(
65-
SEXP x, R_xlen_t i, typename r_vector<r_complex>::underlying_type value) {
66-
SET_COMPLEX_ELT(x, i, static_cast<Rcomplex>(value));
64+
inline void r_vector<r_complex>::set_elt(SEXP x, R_xlen_t i,
65+
r_vector::underlying_type value) {
66+
COMPLEX(x)[i] = static_cast<Rcomplex>(value);
6767
}
6868

6969
typedef r_vector<r_complex> complexes;
@@ -98,8 +98,11 @@ class r_vector<r_complex>::proxy {
9898
proxy(SEXP data, R_xlen_t index)
9999
: data_(data), index_(index), buf_(nullptr), is_altrep_(false) {}
100100

101-
proxy(SEXP data, R_xlen_t index, Rcomplex* buf, bool is_altrep)
102-
: data_(data), index_(index), buf_(buf), is_altrep_(is_altrep) {}
101+
proxy(SEXP data, R_xlen_t index, r_complex* buf, bool is_altrep)
102+
: data_(data),
103+
index_(index),
104+
buf_(reinterpret_cast<Rcomplex*>(buf)),
105+
is_altrep_(is_altrep) {}
103106

104107
operator r_complex() const {
105108
if (is_altrep_ && buf_ != nullptr) {

inst/include/cpp11/r_complex.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ inline void writable::r_vector<r_complex>::push_back(r_complex value) {
4343
this->reserve(this->capacity_ == 0 ? 1 : this->capacity_ * 2);
4444
}
4545

46-
Rcomplex r_value = static_cast<Rcomplex>(value);
47-
4846
if (this->data_p_ != nullptr) {
49-
this->data_p_[this->length_] = r_value;
47+
this->data_p_[this->length_] = static_cast<Rcomplex>(value);
5048
} else {
51-
this->set_elt(this->data_, this->length_, r_value);
49+
set_elt(this->data_, this->length_, value);
5250
}
5351

5452
++this->length_;

inst/include/cpp11/r_vector.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ class r_vector : public cpp11::r_vector<T> {
237237
void push_back(T value);
238238
/// Implemented in `strings.hpp`
239239
void push_back(const named_arg& value);
240+
// Implemented in `complexes.hpp`
241+
void push_back(const std::complex<double>& value);
240242
void pop_back();
241243

242244
void resize(R_xlen_t count);

0 commit comments

Comments
 (0)