As the answer to my StackOverflow question says.
This example shows that the documentation could be improved.
[[cpp11::register]] integers dummyexample(integers x1, integers x2) {
int n = x1.size();
writable::integers y1(n);
writable::integers y2(n);
// add content to y2
// y2_1 = x2_1^2, y2_2 = x2_2^2, ...
for (int i = 0; i < n; i++) { y2[i] = pow(x2[i], 2); }
// then
for (int i = 0; i < n; i++) {
// error: ambiguous overload for ‘operator=’
// y1[i] = y2[i];
// this should resolve the ambiguity
// y1.at(i) = y2.at(i);
// not really, also error: ambiguous overload for ‘operator=’
// maybe
// y1.operator[](i).operator=(y2.operator[](i));
// not either
// int temp = y2[i];
// y1[i] = temp;
// 0 + y2_i works, but why?
y1[i] = 0 + y2[i];
}
return y1;
}
Taking from SamR's answer:
y1[i] and y2[i] are elements of writable integer vectors, and are of type cpp11::writable::r_vector::proxy. It appears that the equals operator for this type has been defined in two places:
- r_vector.hpp line 241: proxy& operator=(const T& rhs);
- integers.hpp line 59: inline typename r_vector<int>::proxy& r_vector<int>::proxy::operator=(const int& rhs)
Reactions are currently unavailable
As the answer to my StackOverflow question says.
This example shows that the documentation could be improved.
[[cpp11::register]] integers dummyexample(integers x1, integers x2) { int n = x1.size(); writable::integers y1(n); writable::integers y2(n); // add content to y2 // y2_1 = x2_1^2, y2_2 = x2_2^2, ... for (int i = 0; i < n; i++) { y2[i] = pow(x2[i], 2); } // then for (int i = 0; i < n; i++) { // error: ambiguous overload for ‘operator=’ // y1[i] = y2[i]; // this should resolve the ambiguity // y1.at(i) = y2.at(i); // not really, also error: ambiguous overload for ‘operator=’ // maybe // y1.operator[](i).operator=(y2.operator[](i)); // not either // int temp = y2[i]; // y1[i] = temp; // 0 + y2_i works, but why? y1[i] = 0 + y2[i]; } return y1; }Taking from SamR's answer:
y1[i] and y2[i] are elements of writable integer vectors, and are of type cpp11::writable::r_vector::proxy. It appears that the equals operator for this type has been defined in two places: