Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::max_element fails on writable vectors #334

Closed
thomasp85 opened this issue Aug 28, 2023 · 0 comments · Fixed by #389
Closed

std::max_element fails on writable vectors #334

thomasp85 opened this issue Aug 28, 2023 · 0 comments · Fixed by #389

Comments

@thomasp85
Copy link
Member

Using the std::max_element() algorithm on a writable vector results in a compile error. The error is not present when using a non-writable vector. It is speculated that the following commit made it possible on the standard vectors and need to be applied to the writable versions as well: 686ae04

#include <cpp11/doubles.hpp>
[[cpp11::register]]
void test() {
  cpp11::writable::doubles foo = {1, 2, 3, 4, 5};
  std::max_element(foo.begin(), foo.end());
}

Compiling the above yields the following error:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/max_element.h:34:25: error: object of type 'cpp11::writable::r_vector<double>::iterator' cannot be assigned because its copy assignment operator is implicitly deleted
                __first = __i;
                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/max_element.h:44:19: note: in instantiation of function template specialization 'std::__max_element<std::__less<cpp11::writable::r_vector<double>::proxy> &, cpp11::writable::r_vector<double>::iterator>' requested here
    return _VSTD::__max_element<_Comp_ref>(__first, __last, __comp);
                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/max_element.h:52:19: note: in instantiation of function template specialization 'std::max_element<cpp11::writable::r_vector<double>::iterator, std::__less<cpp11::writable::r_vector<double>::proxy>>' requested here
    return _VSTD::max_element(__first, __last,
                  ^
code.cpp:4:8: note: in instantiation of function template specialization 'std::max_element<cpp11::writable::r_vector<double>::iterator>' requested here
  std::max_element(foo.begin(), foo.end());
       ^
/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/cpp11/include/cpp11/r_vector.hpp:259:21: note: copy assignment operator of 'iterator' is implicitly deleted because field 'data_' is of reference type 'const cpp11::writable::r_vector<double> &'
    const r_vector& data_;
                    ^
1 error generated.

Whereas this compiles fine

void test(cpp11::doubles foo) {
  std::max_element(foo.begin(), foo.end());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant