Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move the conditional to operator T()
  • Loading branch information
eddelbuettel committed Apr 9, 2026
commit 97147633824d9310fc76ddc5c6b7018fe3841ad4
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* DESCRIPTION (Version, Date): Roll micro version and date
* inst/include/Rcpp/Nullable.h (T): Also add 'operator T()'
(conditional on R (>= 4.3.0) as older versions croak)

2026-04-08 Dirk Eddelbuettel <edd@debian.org>

Expand Down
2 changes: 2 additions & 0 deletions inst/include/Rcpp/Nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace Rcpp {
return m_sexp;
}

#if R_VERSION > R_Version(4,3,0)
/**
* operator T() to return nullable object
*
Expand All @@ -90,6 +91,7 @@ namespace Rcpp {
checkIfSet();
return Rcpp::as<T>(m_sexp);
}
#endif

/**
* get() accessor for object
Expand Down
2 changes: 0 additions & 2 deletions inst/tinytest/cpp/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,13 @@ SEXP testNullableIsUsable(const Nullable<NumericMatrix>& M) {
}
}

#if R_VERSION > R_Version(4,3,0)
// [[Rcpp::export]]
String testNullableString(Rcpp::Nullable<Rcpp::String> param = R_NilValue) {
if (param.isNotNull())
return String(param);
else
return String("");
}
#endif

// [[Rcpp::export]]
void messageWrapper(SEXP s) {
Expand Down
6 changes: 2 additions & 4 deletions inst/tinytest/test_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ expect_equal( testNullableIsUsable(M), M)
expect_true(is.null(testNullableIsUsable(NULL)))

## test.NullableString <- function() {
if (getRversion() > "4.3.0") {
expect_equal(testNullableString(), "")
expect_equal(testNullableString("blah"), "blah")
}
expect_equal(testNullableString(), "")
expect_equal(testNullableString("blah"), "blah")

# test.bib <- function() {
expect_true(nchar(Rcpp:::bib()) > 0, info="bib file")
Expand Down
Loading