C++11 in ROOT

Hi, I’ve recently learned of two wonderful features of C++11: the auto keyword and range-based for loops. On my local machine (up to date), I can use these features in compiled macros, but it doesn’t work in CINT. I would also like to use the code on a remote batch machine which only has older versions of ROOT, and I don’t know if it would work. I don’t fully understand the relation there, so if an expert can provide some details, I would appreciate it.

Specifically, I’d like to know: when can I use C++11 features in ROOT? Does it depend on what was used to compile ROOT, are there ./configure switches that are necessary? Do I need a late enough version of ROOT?


Sooner than you can think :slight_smile: cling does understand C++11, for example (that’s what I have with --enable-cling):

[quote]root [0] std::vector a;
root [1] auto i = a.begin();
//here it produces a warning at the moment
root [2] int arr[] = {1,2,3,4};
root [3] for (auto i : arr) std::cout<<i<<std::endl;[/quote]

It’s a pity it does not understand decltype though (why??)

With my current ROOT instalation (which was not done with --enable-cling), I can still compile macros which use C++11 extensions, but I get warnings like this:

/Users/jfcaron/Projects/TRIUMFBeamTest/CC_algostudy/./algorithms.C:55:8: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  for( auto cluster : potential_clusters)
/Users/jfcaron/Projects/TRIUMFBeamTest/CC_algostudy/./algorithms.C:55:21: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for( auto cluster : potential_clusters)

The macro works fine. Where exactly do I send the -Wc++11-extensions option, if I am compiling from a non-compiled macro using “.L algorithms.C+”? I would like to get rid of the warnings.


Hi Jean-Francois,

You can either compile ROOT in C++11 mode (–enable-cxx11) or you can pass the flags as an extra flag to those use to build ROOT or you can add it the ACLiC command line (see gSystem->Set/GetMakeSharedLib)