Skip to content

Commit 9659f16

Browse files
committed
Some more checking in the ChildVector class
1 parent 35e2f68 commit 9659f16

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

inst/include/Rcpp/vector/ChildVector.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,30 @@ class ChildVector : public T {
3939

4040
inline ChildVector& operator=(const ChildVector& other) {
4141
if (this != &other) {
42-
SET_VECTOR_ELT(parent, i, other.get__());
42+
this->set__(other);
43+
if (parent != NULL && !Rf_isNull(parent)) {
44+
SET_VECTOR_ELT(parent, i, other);
45+
}
4346
}
4447
return *this;
4548
}
4649

4750
inline ChildVector& operator=(const T& other) {
48-
SET_VECTOR_ELT(parent, i, other);
51+
this->set__(other);
52+
if (parent != NULL && !Rf_isNull(parent)) {
53+
SET_VECTOR_ELT(parent, i, other);
54+
}
55+
return *this;
56+
}
57+
58+
template <typename U>
59+
inline ChildVector& operator=(const U& other) {
60+
Shield<SEXP> wrapped( wrap(other) );
61+
T vec = as<T>(wrapped);
62+
this->set__(vec);
63+
if (parent != NULL && !Rf_isNull(parent)) {
64+
SET_VECTOR_ELT(parent, i, vec);
65+
}
4966
return *this;
5067
}
5168

inst/unitTests/runit.ListOf.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if (.runThisTest) {
4141
}
4242

4343
test.ListOf.assign <- function() {
44+
x <- list( c(1, 5), c(2, 6), c(3, 7) )
4445
test_assign(x, 100, "apple")
4546
checkIdentical( x[[2]], 100 )
4647
}

0 commit comments

Comments
 (0)