Skip to content
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cpp11 (development version)

* Added `x.empty()` method to check if a vector is empty (@sbearrows, #182)
* New `cpp11::na()` function to return the NA sentinals for R objects(@sbearrows, #179)
* Incorrectly formatted cpp11 decorators now output a more informative error message (@sbearrows, #127)
* Generated registration code now uses C collation to avoid spurious diffs from `tools::package_native_routine_registration_skeleton()` (@sbearrows, #171)
Expand Down
10 changes: 10 additions & 0 deletions cpp11test/src/test-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ context("list-C++") {
expect_true(first[0] == 1);
expect_true(first[1] == 2);
}

test_that("empty() works") {
cpp11::writable::list x;

expect_true(x.empty());

cpp11::writable::list y(1);

expect_false(y.empty());
}
}
7 changes: 7 additions & 0 deletions inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class r_vector {

operator sexp() const;

bool empty() const;

/// Provide access to the underlying data, mainly for interface
/// compatibility with std::vector
SEXP data() const;
Expand Down Expand Up @@ -389,6 +391,11 @@ inline r_vector<T>::operator SEXP() const {
return data_;
}

template <typename T>
inline bool r_vector<T>::empty() const {
return (!(this->size() > 0));
}

template <typename T>
inline r_vector<T>::operator sexp() const {
return data_;
Expand Down