[Rcpp-devel] variadic templates

Romain François francoisromain at free.fr
Tue Jan 5 10:15:06 CET 2010


Hello,

I've update the conditional compiling logic so that the package may 
build on gcc < 4.3, with less functionalities since variadic templates 
were added with this release.

We still need something to generate this line of the Makevars :

PKG_CPPFLAGS += -I. -std=c++0x

-std=c++0x is only valid from gcc 4.3, so people who want to build the 
package but do not have access to gcc >= 4.3.O can just replace the line 
with this :

PKG_CPPFLAGS += -I.

I've also added Rcpp::capabilities to query the capabilities of the 
package.

For example on my system I have :

$ Rscript -e "Rcpp:::capabilities()"
variadic templates  initializer lists
               TRUE               TRUE

I'll talk about what I want to do with initializer lists later.

Romain

On 01/03/2010 09:53 AM, Romain François wrote:
> On 01/02/2010 10:17 PM, Dirk Eddelbuettel wrote:
>>
>> On 2 January 2010 at 21:45, Romain François wrote:
>> | Hi,
>> |
>> | they are really nice. they provide some sort of ellipsis in the template
>> | argument.
>> |
>> | unfortunately, they are not part of the current standard, but in the
>> | forthcoming new standard c++0x. See
>> | http://en.wikipedia.org/wiki/C%2B%2B0x#Variadic_templates
>> |
>> | But, gcc has many of c++0x features covered.
>> | http://gcc.gnu.org/projects/cxx0x.html
>> |
>> | Why should we are about them. For example we want to mimic making this
>> | call:
>> |
>> |>   call( "rnorm", 10L, 0.0, 2.0 )
>> | rnorm(10L, 0, 2)
>> |
>> | in C++, we (as soon as I can commit it) have the Language class, and I'd
>> | like calling it something like :
>> |
>> | Language obj( "rnorm", 10, 0.0, 2.0 ) ;
>> |
>> | The wrap functions provide conversion of each element to a SEXP, and
>> | variadic templates would take care of the rest.
>> |
>> | This needs this in the Makevars :
>> |
>> | PKG_CPPFLAGS += -I. -std=c++0x
>> |
>> | and presumably also in RcppCxxFlags
>> |
>> |
>> | This is available as of GCC 4.3, so I guess we could #ifdef this somehow ?
>> |
>> | Ideas ?
>>
>> I am generally in favour. The damn C++ standard and C++ implementations move
>> glacially. Just recently I did toy with something at work -- it may just have
>> standard hash_map (or now: unordered_map) and I had three possibly setups:
>> Boost, C++'s tr1 which is still, and also the -stc++0x you suggest here.
>>
>> However -- I know that I am for example a user of Rcpp in one setting where I
>> am forced to use a g++ 3.4.* vintage (!!).  So we shouldn't jump too early
>> and require ultra-modern compilers.
>>
>> So that leaves us with #ifdef / configure logic which could be more work.
>> But if we shield it properly and don't break the old compilers / interfaces,
>> we can give it a shot.
>>
>> Dirk
>
> I've commited. Currently using a CXX0X define in RcppCommon.h that is
> hardcoded. I hope someone can help me generate the define from configure.
>
> Language obj( "rnorm", 10, 0.0, 2.0 ) ;
>
> works like a charm
>
> Romain
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/IW9B : C++ exceptions at the R level
|- http://tr.im/IlMh : CPP package: exposing C++ objects
`- http://tr.im/HlX9 : new package : bibtex



More information about the Rcpp-devel mailing list