Rootcint && C++11

Hi,
I have a class that I also generate a dictionary for, using rootcint. Well recently, I needed to use some of the new features in the C++11 and added unordered_map as a data member in my class. But when I went on to get rootcint to generate a dictionary for it, I get this error:

Generating dictionary MyClassDict.cpp... Error: cannot open file "unordered_map" MyClass.h:12: Error: Symbol unordered_map is not defined in current scope MyClass.h:81: Error: Symbol long,PopData is not defined in current scope MyClass.h:81: Error: Symbol popMap is not defined in current scope MyClass.h:81: Warning: Error occurred during reading source files Warning: Error occurred during dictionary source generation !!!Removing MyClassDict.cpp MyClassDict.h !!! Error: rootcint: error loading headers...

The line it is complaining about in my MyClass.h is the include of the std::unordered_map:
#include <unordered_map>

Of which my compiler has no problem referencing this header in my other non-root related code.

In my makefile for generating root standalone executables, I have this:

MyClassDict.cpp: MyClass.h MyClassLinkDef.h @echo "Generating dictionary $@..." @rootcint -f MyClassDict.cpp -c MyClass.h MyClassLinkDef.h

where MyClassLinkDef.h has this:

[code]
#ifdef CINT

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class MyClass+;

#endif[/code]

I do compile my code with the -std=c++11 option, where my g++ version is:
g++ (GCC) 4.8.2 20131017 (Red Hat 4.8.2-1)

Does not rootcint support C++11? Is there some option I should be passing to rootcint for it to recognize this unordered_map header? The root version I have is ROOT 5.34/10.

BTW the unordered_map is also available without the -std=c++11 option. If I use the namespace tr1, it will find it, that is if I referenced the header as:
#include <tr1/unordered_map>

But the rootcint still can’t find this header:

Generating dictionary MyClassDict.cpp... Error: cannot open file "tr1/unordered_map" MyClass.h:12:

Help? :frowning:

I think, if you are brave enough to mix good old CINT and C++11, just use a well-known Pimpl idiom to hide from CINT too smart/modern things.

You can read about Pimpl here: en.wikipedia.org/wiki/Pimpl.

I was able to use unordered map (see the attachment).
Actually, CINT does not/is not expected to support C++11, so if you do not like to spend your time on workarounds, probably you have to switch to ROOT 6 (trunk) with cling as interpreter, it should have less problems with modern C++/C++ library.

P.S. I think ClassDef/ClassImp are irrelevant to the solution I’m demonstrating, but let it be - just to prove we can use them.
tst.C (72 Bytes)
A.h (617 Bytes)
A.cxx (626 Bytes)

When will Root 6 be officially released? I’m hesitant to try it; worried that it’s not ‘production’ ready (e.g. unstable) and don’t have the time to be trouble-shooting it.

I’m trying to use a hashmap for faster access which is why I was trying to use this unordered_map. But now that it’s been revealed to me that the C++11 is not supported in the most recent version of root, I tried the THashTable. But the performance is even worst (swapping pages alot and have no idea why!).

[quote=“jade2”]When will Root 6 be officially released? I’m hesitant to try it; worried that it’s not ‘production’ ready (e.g. unstable) and don’t have the time to be trouble-shooting it.

I’m trying to use a hashmap for faster access which is why I was trying to use this unordered_map. But now that it’s been revealed to me that the C++11 is not supported in the most recent version of root, I tried the THashTable. But the performance is even worst (swapping pages alot and have no idea why!).[/quote]

The beta release will be this month, in a couple of weeks I guess. If you need something to be fast, you have to use ACLiC (or a standalone compiled program) and in this case there is no big difference - ROOT 6 or ROOT 5.34 - you can always hide non-trivial things from CINT as I demonstrated.

[quote=“tpochep”]
The beta release will be this month, in a couple of weeks I guess. If you need something to be fast, you have to use ACLiC (or a standalone compiled program) and in this case there is no big difference - ROOT 6 or ROOT 5.34 - you can always hide non-trivial things from CINT as I demonstrated.[/quote]

Hi tpochep,
I am using ACLic (and also have tried compiling it as a standalone program). Maybe I’m misunderstanding something about how I’m using root. It might help if I try to exSo I have this C++ data structure (which I’m trying to have a hash map as a data member), by which I fill by accessing selective data from a root tree. I take a set of this data and put it in an stl vector (which I later have to do manipulations on). Now this C++ data structure is compiled into a share object. I have a script that uses this C++ data structure. So when I run this script, I load up the shared object (that contains this class using gSystem->Load(“libMyClass”) command on root cmdline) and then execute .x myScript.C++. The problem is that I can’t compile libMyClass.so when trying to create a dictionary to MyClass (which I need to trigger rootcint in my makefile and this is where the problem of having unordered_map in MyClass begins).

Now you may ask, why do I need to create a dictionary to MyClass. And maybe that’s where I might have a misunderstanding of how to use root. So it might help for me to ask some questions here. I currently have MyClass inherit TObject and ClassDef, ClassImp, etc for root to recognize is (am I wrong about this?? Maybe this is where my assumption is in error). That is my class looks like this:

class MyClass: public TObject { ... ClassDef(MyClass,1) };

Some where in myScript.C, I need to instantiate vector and fill it with selective data from the root tree. Now I thought that for me to use it within an stl container within the root environment, I’d have to generate a dictionary for this class, when using ACLic. Am I wrong about this? Or can I get away with MyClass being rid of Tobject, ClassDef, etc and hence not have to generate a dictionary for it and still have myScript.c instantiate vector???

Have you tried the code sample I’ve attached in my reply? While I’m not using any external makefile or rootcint manually, CINT still parses/“preprocesses” my class definition and it does not complain about any C++11 construct/container, since they are all hidden from CINT. In my test macro I’m:

  1. compiling a shared library for my class A (using C++11 structures/syntax internally)
  2. creating and using an object of type A in a CINT’s environment (== interpreted).

May be it can help if you do the same?
Use an opaque pointer to void for CINT, initialise and work with this pointer the way you like with syntax you like in #ifndef CINT blocks?

Hi tpochep,
I didn’t really want to have to go through the trouble of hiding it. It become cumbersome to have to do it for several objects. I decided to strip my class of TObject and ClassDef, ClassImp, etc and hence didn’t need to create a dictionary for my class and just ran it as a standalone executable so that I could use some of the C++11 features. Thanks for the help though!