Skip to content

Conversation

romainfrancois
Copy link
Collaborator

closes #56

cpp11::cpp_function('
cpp11::writable::logicals bools(){ 
  cpp11::writable::logicals x(1);
  x[0] = true;
  return x;
  } 
', quiet = FALSE)
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Users/romainfrancois/.R/library/4.0/cpp11/include  -I/usr/local/include   -fPIC  -Wall -O3 -Wall -Wimplicit-int-float-conversion -c /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/code_0.cpp -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/code_0.o
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Users/romainfrancois/.R/library/4.0/cpp11/include  -I/usr/local/include   -fPIC  -Wall -O3 -Wall -Wimplicit-int-float-conversion -c /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/cpp11.cpp -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/cpp11.o
#> clang++ -mmacosx-version-min=10.13 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/code_0.so /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/code_0.o /private/var/folders/4b/hn4fq98s6810s4ccv2f9hm2h0000gn/T/RtmpHcARkQ/file494f394b9440/src/cpp11.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
bools()
#> [1] TRUE

Created on 2020-07-24 by the reprex package (v0.3.0.9001)

Other things could be useful, e.g. cpp11::writable::doubles::operator=<int> .

The list one could be magical and go though as_cpp<U> but that might be good to leave it as explicit with SEXP

@jimhester
Copy link
Member

Thanks, the templated operator is a good solution!

Can you add a test or two for it in https://github.com/r-lib/cpp11/blob/master/cpp11test/src/test-logicals.cpp, then I think this can be merged.

@romainfrancois
Copy link
Collaborator Author

I have added this:

test_that("writable::logicals::proxy::operator=(bool)") {
    cpp11::writable::logicals y(2);

    y[0] = false;
    y[1] = true;
    expect_true(y[0] == TRUE);
    expect_true(y[1] == FALSE);
  }

but I'm not sure how to run the cpp11test tests. It does not look they are run as part of devtools::test() on cpp11 ?

@jimhester
Copy link
Member

They will be if you install cpp11test first. Alternatively (this is usually how I do it during development) I set my working directory / project to cpp11test, then run the C++ tests with devtools::test() from there.

@jimhester jimhester merged commit 58f571f into r-lib:master Jul 27, 2020
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 this pull request may close these issues.

writable::logicals::proxy = bool
2 participants