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

allow = <bool> in writables::logicals. #57

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cpp11test/src/test-logicals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ context("logicals-C++") {

UNPROTECT(1);
}
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);
}
test_that("is_na(Rboolean)") {
Rboolean x = TRUE;
expect_true(!cpp11::is_na(x));
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/doubles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ typedef r_vector<double> doubles;
namespace writable {

template <>
inline typename r_vector<double>::proxy& r_vector<double>::proxy::operator=(
template <>
inline typename r_vector<double>::proxy& r_vector<double>::proxy::operator=<double>(
const double& rhs) {
if (is_altrep_) {
// NOPROTECT: likely too costly to unwind protect every set elt
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/integers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ typedef r_vector<int> integers;
namespace writable {

template <>
inline typename r_vector<int>::proxy& r_vector<int>::proxy::operator=(const int& rhs) {
template <>
inline typename r_vector<int>::proxy& r_vector<int>::proxy::operator=<int>(const int& rhs) {
if (is_altrep_) {
// NOPROTECT: likely too costly to unwind protect every set elt
SET_INTEGER_ELT(data_, index_, rhs);
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ typedef r_vector<SEXP> list;
namespace writable {

template <>
inline typename r_vector<SEXP>::proxy& r_vector<SEXP>::proxy::operator=(const SEXP& rhs) {
template <>
inline typename r_vector<SEXP>::proxy& r_vector<SEXP>::proxy::operator=<SEXP>(const SEXP& rhs) {
SET_VECTOR_ELT(data_, index_, rhs);
return *this;
}
Expand Down
10 changes: 9 additions & 1 deletion inst/include/cpp11/logicals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ typedef r_vector<Rboolean> logicals;
namespace writable {

template <>
inline typename r_vector<Rboolean>::proxy& r_vector<Rboolean>::proxy::operator=(
template <>
inline typename r_vector<Rboolean>::proxy& r_vector<Rboolean>::proxy::operator=<Rboolean>(
const Rboolean& rhs) {
if (is_altrep_) {
SET_LOGICAL_ELT(data_, index_, rhs);
Expand All @@ -58,6 +59,13 @@ inline typename r_vector<Rboolean>::proxy& r_vector<Rboolean>::proxy::operator=(
return *this;
}

template <>
template <>
inline typename r_vector<Rboolean>::proxy& r_vector<Rboolean>::proxy::operator=<bool>(
const bool& rhs) {
return operator=(rhs ? TRUE : FALSE);
}

template <>
inline r_vector<Rboolean>::proxy::operator Rboolean() const {
if (p_ == nullptr) {
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ class r_vector : public cpp11::r_vector<T> {
public:
proxy(SEXP data, const R_xlen_t index, T* const p, bool is_altrep);

proxy& operator=(const T& rhs);
template <typename U>
proxy& operator=(const U& rhs);
proxy& operator+=(const T& rhs);
proxy& operator-=(const T& rhs);
proxy& operator*=(const T& rhs);
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/raws.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ typedef r_vector<uint8_t> raws;
namespace writable {

template <>
inline typename r_vector<uint8_t>::proxy& r_vector<uint8_t>::proxy::operator=(
template <>
inline typename r_vector<uint8_t>::proxy& r_vector<uint8_t>::proxy::operator=<uint8_t>(
const uint8_t& rhs) {
if (is_altrep_) {
// NOPROTECT: likely too costly to unwind protect every set elt
Expand Down
3 changes: 2 additions & 1 deletion inst/include/cpp11/strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ typedef r_vector<r_string> strings;
namespace writable {

template <>
inline typename r_vector<r_string>::proxy& r_vector<r_string>::proxy::operator=(
template <>
inline typename r_vector<r_string>::proxy& r_vector<r_string>::proxy::operator=<r_string>(
const r_string& rhs) {
unwind_protect([&] { SET_STRING_ELT(data_, index_, rhs); });
return *this;
Expand Down