Map<string, string> in CINT

Hi all,

I was wondering what is the official way to have CINT understand map<string, string>; I’ve tried using #pragma link C++ class std::map<std::string, std::string>; but this doesn’t seem to work.

Here’s my short test script:

#if !defined(__CINT__) || defined(__MAKECINT__)
#include <iostream>
#include <vector>
//#include <string>
//#include <map>
int main()
#endif


#if  defined(__CINT__) 
#pragma link C++ class std::map<std::string, std::string>;
void testCINT()
#endif


{
  std::cout << "bla " << std::endl;
#if !defined(__CINT__) || defined(__MAKECINT__)
  std::cout << "!__CINT__ || __MAKECINT__" << std::endl;
#endif
#if  defined(__MAKECINT__)
  std::cout << "__MAKECINT__" << std::endl;
#endif
#if  defined(__CINT__)
  std::cout << "__CINT__" << std::endl;

  std::vector<int> a;
  a.push_back(1);
  std::cout << a[0] << std::endl;

  std::vector<string> b;
  b.push_back("bla");
  std::cout << b[0] << std::endl;

  std::map<string, string> c;
  c["bla"] = "bla";
  std::cout << c["bla"] << std::endl;
#endif
}

Which replies:
Error: link requested for unknown class std::mapstd::string,std::string testCINT.C:11:

I assume I need to build a dictionary for map<string, string>, but that such a dictionary is already built for e.g. map<string, int>?

Cheers,
N.

[quote]Error: link requested for unknown class std::mapstd::string,std::string testCINT.C:11: [/quote]You need to uncomment the include for the header of both map and string …

Philippe.

Hi Philippe,

I added it and this is what I get:
Error: Can’t call map<string,string,less,allocator<pair<const string,string> > >::operator in current scope testCINT.C:40:
Possible candidates are…
(in map<string,string,less,allocator<pair<const string,string> > >)
Error: improper lvalue testCINT.C:40:
(class string)49957104
*** Interpreter error recovered ***

#if !defined(__CINT__) || defined(__MAKECINT__)
#include <iostream>
#include <vector>
#include <string>
#include <map>
int main()
#endif


#if  defined(__CINT__) 
#include <map>
#include <string>
#pragma link C++ class std::map<std::string, std::string>;
void testCINT()
#endif


{
  std::cout << "bla " << std::endl;
#if !defined(__CINT__) || defined(__MAKECINT__)
  std::cout << "!__CINT__ || __MAKECINT__" << std::endl;
#endifa
#if  defined(__MAKECINT__)
  std::cout << "__MAKECINT__" << std::endl;
#endif
#if  defined(__CINT__)
  std::cout << "__CINT__" << std::endl;

  std::vector<int> a;
  a.push_back(1);
  std::cout << a[0] << std::endl;

  std::vector<string> b;
  b.push_back("bla");
  std::cout << b[0] << std::endl;

  std::map<string, string> c;
  string key   = "bla";
  string value = "mybla";
  c[key] = value;
  // c.insert( pair<std::string, std::string>("bla", "mybla") );
  //std::cout << c["bla"] << std::endl;
#endif
}

Nir

[quote]Error: Can’t call map<string,string,less,allocator<pair<const string,string> > >::operator in current scope testCINT.C:40:
[/quote]This now means that you have not loaded the dictionary for map<string,string>. What are the exact step you are executing?

Philippe.

Hi Philippe,

I simply execute the code:
.x testCINT.C

N.

Hi,

So you do not generate the dictionary for the map.
You can either just compile your whole script ( .x testCINT.C+ ) or compile a file containing just the dictionary request/* loader.C */ #include <string> #include <map> #ifdef __MAKECINT__ #pragma link C++ class std::map<std::string, std::string>; #endifand use.L loader.C+ .x testCINT.C

Cheers,
Philippe.

Hi Philippe,

Thanks, this works.

N.