@@ -58,20 +58,12 @@ class XPtr :
5858
5959 typedef StoragePolicy<XPtr> Storage;
6060
61- #if defined(RCPP_USING_CXX11)
62-
6361 /* *
6462 * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
6563 *
6664 * @param xp external pointer to wrap
6765 */
68- explicit XPtr (SEXP x) {
69- if (TYPEOF (x) != EXTPTRSXP) {
70- const char * fmt = " Expecting an external pointer: [type=%s]." ;
71- throw ::Rcpp::not_compatible (fmt, Rf_type2char (TYPEOF (x)));
72- }
73- Storage::set__ (x);
74- };
66+ explicit XPtr (SEXP x) { checked_set (x); };
7567
7668 /* *
7769 * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
@@ -80,31 +72,12 @@ class XPtr :
8072 * @param tag tag to assign to external pointer
8173 * @param prot protected data to assign to external pointer
8274 */
83- explicit XPtr (SEXP x, SEXP tag, SEXP prot) : XPtr (x) {
84- R_SetExternalPtrTag ( x, tag);
85- R_SetExternalPtrProtected (x, prot);
86- };
87-
88- #else
89-
90- /* *
91- * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
92- *
93- * @param xp external pointer to wrap
94- */
95- explicit XPtr (SEXP x, SEXP tag = R_NilValue, SEXP prot = R_NilValue) {
96- if (TYPEOF (x) != EXTPTRSXP) {
97- const char * fmt = " Expecting an external pointer: [type=%s]." ;
98- throw ::Rcpp::not_compatible (fmt, Rf_type2char (TYPEOF (x)));
99- }
100-
101- Storage::set__ (x);
102- R_SetExternalPtrTag ( x, tag);
75+ explicit XPtr (SEXP x, SEXP tag, SEXP prot) {
76+ checked_set (x);
77+ R_SetExternalPtrTag (x, tag);
10378 R_SetExternalPtrProtected (x, prot);
10479 };
10580
106- #endif
107-
10881 /* *
10982 * creates a new external pointer wrapping the dumb pointer p.
11083 *
@@ -213,6 +186,16 @@ class XPtr :
213186 }
214187
215188 void update (SEXP) {}
189+
190+ private:
191+ inline void checked_set (SEXP x) {
192+ if (TYPEOF (x) != EXTPTRSXP) {
193+ const char * fmt = " Expecting an external pointer: [type=%s]." ;
194+ throw ::Rcpp::not_compatible (fmt, Rf_type2char (TYPEOF (x)));
195+ }
196+ Storage::set__ (x);
197+ }
198+
216199};
217200
218201} // namespace Rcpp
0 commit comments