Vector< pair<> >

Hi all,
Could someone please explain why the below code is not working with root? It works perfectly with g++(just remove all // ) . I know it has to do with CINT . Can someone please guide me to a solution?
Thanks in advance…

Abhisek

// macro test.cc
//#include <stdio.h>
#include
#include
//using namespace std;

//int main(void) //
void test()
{
vector< pair<int,double> > my_data;

for(int i=1; i<10; i++)
{
my_data.push_back( make_pair( i, (double)i+2.2 ) );
}
//cout << my_data[1]->second<< endl;

for( vector< pair<int,double> >::iterator iter= my_data.begin(); iter!=my_data.end(); iter++)
{
cout << iter->first << " " << iter->second << endl;
}

}

Hi,

You could try running your code as follows:

which will compile your code before executing it (so it even runs faster). It works in ROOT v5.28.00.

If the int in your pair<int,double> is unique, I’d recommend using map<int, double>. If it’s not, you could use multimap<int, double>. However if you want to preserve the order (which I assume is the reason why you use a vector) you could use tr1::unordered_map and tr1::unordered_multimap. However, I don’t know if this is possible as is in CINT. Perhaps you could try to include gInterpreter->AddIncludePath() statements to point to the tr1 header files.

Cheers,
Karolos

See the post of “Tue Mar 01, 2011 14:24” in this thread: [url]Vectors in 5.28.00

Thanks, Pepe. I’ll post the good news also here: it’s fixed! Thanks for your report, Abhisek!

Cheers, Axel.