Skip to content

Commit 532cd3f

Browse files
committed
Workaround issue constructing logical vectors of length 1 from 'false'
Fixes #187
1 parent be4e586 commit 532cd3f

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

cpp11test/src/test-logicals.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ context("logicals-C++") {
134134
expect_true(cpp11::is_na(y));
135135
}
136136

137+
test_that("FALSE and false") {
138+
cpp11::writable::logicals x{FALSE};
139+
expect_true(x.size() == 1);
140+
expect_true(x[0] == FALSE);
141+
142+
cpp11::writable::logicals y{false};
143+
expect_true(y.size() == 1);
144+
expect_true(y[0] == FALSE);
145+
}
146+
137147
// test_that("writable::logicals(ALTREP_SEXP)") {
138148
// SEXP x = PROTECT(R_compact_intrange(1, 5));
139149
//// Need to find (or create) an altrep class that implements duplicate.

cpp11test/src/test-strings.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ context("strings-C++") {
132132
UNPROTECT(1);
133133
}
134134

135+
test_that("std::initializer_list<const char*>") {
136+
cpp11::writable::strings x{"foo"};
137+
expect_true(x.size() == 1);
138+
expect_true(x[0] == "foo");
139+
}
140+
141+
test_that("std::initializer_list<std::string>") {
142+
std::string str("foo");
143+
cpp11::writable::strings x{str};
144+
expect_true(x.size() == 1);
145+
expect_true(x[0] == "foo");
146+
}
147+
135148
test_that("NA_STRING constructor") {
136149
cpp11::writable::strings x({NA_STRING});
137150

inst/include/cpp11/logicals.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,5 @@ inline void r_vector<r_bool>::push_back(r_bool value) {
138138
typedef r_vector<r_bool> logicals;
139139

140140
} // namespace writable
141+
141142
} // namespace cpp11

inst/include/cpp11/r_vector.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,14 @@ class r_vector : public cpp11::r_vector<T> {
285285
r_vector(SEXP&& data, bool is_altrep);
286286
r_vector(std::initializer_list<T> il);
287287
r_vector(std::initializer_list<named_arg> il);
288-
r_vector(std::initializer_list<const char*> il);
289-
r_vector(std::initializer_list<std::string> il);
290288

291289
template <typename Iter>
292290
r_vector(Iter first, Iter last);
293291

294292
template <typename V, typename W = has_begin_fun<V>>
295293
r_vector(const V& obj);
296294

297-
r_vector(const R_xlen_t size);
295+
explicit r_vector(const R_xlen_t size);
298296

299297
~r_vector();
300298

@@ -688,7 +686,7 @@ inline r_vector<T>::r_vector(const V& obj) : r_vector() {
688686
}
689687

690688
template <typename T>
691-
inline r_vector<T>::r_vector(R_xlen_t size) : r_vector() {
689+
inline r_vector<T>::r_vector(const R_xlen_t size) : r_vector() {
692690
resize(size);
693691
}
694692

inst/include/cpp11/strings.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ template <>
112112
inline r_vector<r_string>::r_vector(std::initializer_list<r_string> il)
113113
: cpp11::r_vector<r_string>(as_sexp(il)), capacity_(il.size()) {}
114114

115-
template <>
116-
inline r_vector<r_string>::r_vector(std::initializer_list<const char*> il)
117-
: cpp11::r_vector<r_string>(as_sexp(il)), capacity_(il.size()) {}
118-
119-
template <>
120-
inline r_vector<r_string>::r_vector(std::initializer_list<std::string> il)
121-
: cpp11::r_vector<r_string>(as_sexp(il)), capacity_(il.size()) {}
122-
123115
template <>
124116
inline r_vector<r_string>::r_vector(std::initializer_list<named_arg> il)
125117
: cpp11::r_vector<r_string>(safe[Rf_allocVector](STRSXP, il.size())),

0 commit comments

Comments
 (0)