[Rcpp-devel] Rcpp constructor validator help

Anon User rcppdevel at hong-ni.com
Mon Nov 7 15:27:16 CET 2016

Thank you Dirk. I am very new to rcpp devel so I apologize if my terminology is inaccurate. 

By “Constructor Validator”, I was referring to the validator function pointer used to "implement dispatch to the appropriate constructor when multiple constructors taking the same number of arguments are exposed," as mentioned in your book “Seamless R and C++ integration with Rcpp” (page 92) 

The class constructors in question take either two ints, or an int plus an object of class Foo, which has been property converted via as<>() and wrap().

Suggestions and example code will be much appreciated!


p.s. Thank you for your work on Rcpp. I very much enjoyed using it for C++ <-> R interactions. I realized Rcpp has simplified my task of exposing my C++ library to R tremendously.

> On Nov 6, 2016, at 12:33 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
> On 6 November 2016 at 11:36, Anon User wrote:
> | Hi,
> | 
> | 	Could someone point me to documentation or provide an example on how to use constructor validator to handle the following case:
> Could you provide a definition or reference for 'constructor validator'?
> That is not a term we use here regularly.
> | 	class Foo;
> | 
> | 	struct Bar
> | 	{ 
> | 		Bar(const Foo&, int);
> | 		Bar(int,  int);
> | 		…
> | 	};
> | 
> | 	I would like to find a way for the R user to build a Bar object using either one of the constructors. 
> | 
> | 	Your help is much appreciated!
> Well 'Foo' is not something R or Rcpp knows about so you would have to write
> converters first.  See Rcpp-extending for as<>() and wrap().  But I would
> start simpler with basic interfaces using known Rcpp types and/or atomistic
> C++ types.
> Dirk
> -- 
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org

More information about the Rcpp-devel mailing list