Skip to content

Commit cacffe9

Browse files
committed
generate new vector to hold results
1 parent 93f6838 commit cacffe9

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

inst/include/Rcpp/vector/Subsetter.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,23 @@ class SubsetProxy {
228228

229229
public:
230230

231-
#define RCPP_GENERATE_SUBSET_PROXY_OPERATOR(__OPERATOR__) \
232-
template <int RTYPE_OTHER, template <class> class StoragePolicyOther, \
233-
int RHS_RTYPE_OTHER, bool RHS_NA_OTHER, typename RHS_T_OTHER> \
234-
SubsetProxy& operator __OPERATOR__ ( \
235-
const SubsetProxy<RTYPE_OTHER, StoragePolicyOther, RHS_RTYPE_OTHER, \
236-
RHS_NA_OTHER, RHS_T_OTHER>& other) { \
237-
if (other.indices_n == 1) { \
238-
for (int i = 0; i < indices_n; ++i) \
239-
lhs[indices[i]] __OPERATOR__ ## = other.lhs[other.indices[0]]; \
240-
} else if (indices_n == other.indices_n) { \
241-
for (int i = 0; i < indices_n; ++i) \
242-
lhs[indices[i]] __OPERATOR__ ## = other.lhs[other.indices[i]]; \
243-
} else { \
244-
stop("index error"); \
245-
} \
246-
return *this; \
231+
#define RCPP_GENERATE_SUBSET_PROXY_OPERATOR(__OPERATOR__) \
232+
template <int RTYPE_OTHER, template <class> class StoragePolicyOther, \
233+
int RHS_RTYPE_OTHER, bool RHS_NA_OTHER, typename RHS_T_OTHER> \
234+
Vector<RTYPE, StoragePolicy> operator __OPERATOR__ ( \
235+
const SubsetProxy<RTYPE_OTHER, StoragePolicyOther, RHS_RTYPE_OTHER, \
236+
RHS_NA_OTHER, RHS_T_OTHER>& other) { \
237+
Vector<RTYPE, StoragePolicy> result(indices_n); \
238+
if (other.indices_n == 1) { \
239+
for (int i = 0; i < indices_n; ++i) \
240+
result[i] = lhs[indices[i]] __OPERATOR__ other.lhs[other.indices[0]]; \
241+
} else if (indices_n == other.indices_n) { \
242+
for (int i = 0; i < indices_n; ++i) \
243+
result[i] = lhs[indices[i]] __OPERATOR__ other.lhs[other.indices[i]]; \
244+
} else { \
245+
stop("index error"); \
246+
} \
247+
return result; \
247248
}
248249

249250
RCPP_GENERATE_SUBSET_PROXY_OPERATOR(+)

0 commit comments

Comments
 (0)