Re: map<int, float>::iterator

From: Anil Singh <anil79_at_fnal.gov>
Date: Mon, 15 Dec 2008 00:57:50 -0600


Hi,

This is in continuation of the current discussion of map objects in root. Following is a code which works very fine with standard c++ but not with root.

//=============================================================

// This Programs work fine in standart C++.
// But it throw errors when used in root as // follows:

// .L map.cc;
// main();

#include<map>
#include<iostream>

void AddEntryToMap(std::map<int, float>& Map); void PrintTheMap(std::map<int, float>& Map); int main()
{

  std::map<int, float> Map;
  AddEntryToMap(Map);
  PrintTheMap(Map);
}

void AddEntryToMap(std::map<int, float>& Map)
{

  Map[0]=1;
  Map[1]=2.3;
}

void PrintTheMap(std::map<int, float>& Map)
{

  std::map<int, float>::iterator it = Map.begin();   while(it!=Map.end() )
    {

      std::cout<<it->first<<"   "<<it->second<<std::endl;
      it++; 

    }
}
//========================================================

I wonder what the problem is ?

Anil Singh
FermiLab

> Hi,
> 
> It seems that root does not allow us to define a pointer/ iterator
> to map<int, float> object.  If we do following on interactive 
> root mode:
> =============================
> 
> #include<map>
> std::map<int, int>::iterator  iter;
> 
> =============================
> 
> The declaration is accepted without a complaint. On the other hand,
> 
> =============================
> std::map<int, float>::iterator  flt;
> =============================
> 
> this declaration gives an error:
> 
> ----------------------------------------------------------------------------------------------
> Symbol iteratorflt is not defined in current scope (tmpfile) (1)
> ***Interpreter error recovererd***
> ------------------------------------------------------------------------------------------------
> 
> I also had a problem similar to your's when it tried to define a 
> function like:
> 
> void  AddEntryToMap( std::map<int, float>& Map)
> {
>    Map[0] =1;
>    Map[1] =3.2;
> }
> 
> this function when called shot an error, which I can remember at the 
> moment...I will
> send a follow up mail soon.....about it.
> 
> Anil
> 
> 
> 
> 
> 
> 
> 
> 
> ----- Original Message -----
> From: Christopher Jones <c_jones_at_MIT.EDU>
> Date: Sunday, December 14, 2008 6:47 pm
> Subject: Re: [ROOT] map<int, float>::iterator
> To: Anil Singh <anil79_at_fnal.gov>
> Cc: roottalk_at_cern.ch
> 
> 
> > By "not work" do you mean that when you try to dereference the  
> > map<int, float> iterator, you get an error?  Could you paste your error?
> > 
> > I have no problem using map<int, int>s either, but:
> > 
> >  >map<int, float> map1;
> >   >map1[3] = 4.32;  // test values
> >   >map1[4] = 5.67;
> >   >map<int, float>::iterator it = map1.begin();
> > 
> >  >*it;    // same error if you try it->first or it->second
> > Error: Illegal pointer operation (tovalue) (tmpfile):1:
> > (const class map<int,float,less<int>,allocator<pair<const int,float> 
> > 
> >  
> >  >::iterator)0
> > *** Interpreter error recovered ***
> > 
> > I have the same problem making std::vectors of pair< int, float >,  
> 
> > even though I can define pairs and access them just fine.  I think  
> 
> > ROOT has trouble dealing with maps because it can't handle 
> collections 
> >  
> > of pairs (and I think maps are handled as pairs).
> > 
> > On Dec 14, 2008, at 7:08 PM, Anil Singh wrote:
> > 
> > > Hi All,
> > >
> > > I am working with a code that reqire extensive use of
> > > std::map objects .  I was trying to do something like :
> > > //--------------------------
> > > {
> > > #include<map>
> > >  using namespace std;
> > >  std::map<int, int>::iterator int_iter;
> > >  std::map<int, float>::iterator flt_iter;
> > > }
> > > //----------------------------
> > >
> > > It seems that though           "std::map<int, int>::iterator" is  
> 
> > > fine but
> > > "std::map<int, float>::iterator", does not work at all......
> > > Any help is appreciated.
> > > Anil Singh
> > > FermiLab
> > >
> > 
> > Chris Jones
> > c_jones_at_mit.edu
> > 
> > 
> > 
> > 
> > 
> 
Received on Mon Dec 15 2008 - 07:57:59 CET

This archive was generated by hypermail 2.2.0 : Mon Dec 15 2008 - 11:50:02 CET