From fbf104f5c4804606b9e4e1e1a9ff3c62336a1b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Jan 2016 14:08:55 +0100 Subject: [PATCH 1/5] const support for Nullable cargo-culted from many other implementations of `operator SEXP()` --- inst/include/Rcpp/Nullable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/include/Rcpp/Nullable.h b/inst/include/Rcpp/Nullable.h index 67c02f0cc..5bbc0f183 100644 --- a/inst/include/Rcpp/Nullable.h +++ b/inst/include/Rcpp/Nullable.h @@ -76,7 +76,7 @@ namespace Rcpp { * * @throw 'not initialized' if object has not been set */ - inline operator SEXP() { + inline operator SEXP() const { checkIfSet(); return m_sexp; } @@ -86,7 +86,7 @@ namespace Rcpp { * * @throw 'not initialized' if object has not been set */ - inline SEXP get() { + inline SEXP get() const { checkIfSet(); return m_sexp; } From 324e75c9a7f18568fc373394b90e630a3a1815bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Jan 2016 14:15:57 +0100 Subject: [PATCH 2/5] operator SEXP() is forwarded to get() --- inst/include/Rcpp/Nullable.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inst/include/Rcpp/Nullable.h b/inst/include/Rcpp/Nullable.h index 5bbc0f183..c9a4da63e 100644 --- a/inst/include/Rcpp/Nullable.h +++ b/inst/include/Rcpp/Nullable.h @@ -77,8 +77,7 @@ namespace Rcpp { * @throw 'not initialized' if object has not been set */ inline operator SEXP() const { - checkIfSet(); - return m_sexp; + return get(); } /** From ff00bf7353e54b0989567be1ea9320f450f9c999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Jan 2016 14:20:43 +0100 Subject: [PATCH 3/5] use const& in Nullable tests --- inst/unitTests/cpp/misc.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/unitTests/cpp/misc.cpp b/inst/unitTests/cpp/misc.cpp index 452e8c872..eab3ecb14 100644 --- a/inst/unitTests/cpp/misc.cpp +++ b/inst/unitTests/cpp/misc.cpp @@ -179,22 +179,22 @@ void test_stop_variadic() { } // [[Rcpp::export]] -bool testNullableForNull(Nullable M) { +bool testNullableForNull(const Nullable& M) { return M.isNull(); } // [[Rcpp::export]] -bool testNullableForNotNull(Nullable M) { +bool testNullableForNotNull(const Nullable& M) { return M.isNotNull(); } // [[Rcpp::export]] -SEXP testNullableOperator(Nullable M) { +SEXP testNullableOperator(const Nullable& M) { return M; } // [[Rcpp::export]] -SEXP testNullableGet(Nullable M) { +SEXP testNullableGet(const Nullable& M) { return M.get(); } From 563d9683f70c873acbd284b5641e4479f7be2d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Jan 2016 14:25:48 +0100 Subject: [PATCH 4/5] NEWS --- inst/NEWS.Rd | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index bea986564..694688fa8 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -3,6 +3,17 @@ \newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}} \newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}} +\section{Changes in Rcpp version 0.12.4 (2016-01-XX)}{ + \itemize{ + \item Changes in Rcpp API: + \itemize{ + \item \code{Nullable<>::operator SEXP()} and + \code{Nullable<>::get()} now also work for \code{const} objects + (PR \ghpr{417}). + } + } +} + \section{Changes in Rcpp version 0.12.3 (2016-01-10)}{ \itemize{ \item Changes in Rcpp API: From 2c57b986f74609b2621ece5b434d4785462779a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 13 Jan 2016 14:55:56 +0100 Subject: [PATCH 5/5] Revert "operator SEXP() is forwarded to get()" This reverts commit 324e75c9a7f18568fc373394b90e630a3a1815bb. --- inst/include/Rcpp/Nullable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/include/Rcpp/Nullable.h b/inst/include/Rcpp/Nullable.h index c9a4da63e..5bbc0f183 100644 --- a/inst/include/Rcpp/Nullable.h +++ b/inst/include/Rcpp/Nullable.h @@ -77,7 +77,8 @@ namespace Rcpp { * @throw 'not initialized' if object has not been set */ inline operator SEXP() const { - return get(); + checkIfSet(); + return m_sexp; } /**