help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

small question about hash and namespace


From: Faheem Mitha
Subject: small question about hash and namespace
Date: Sun, 03 Oct 2004 04:32:00 GMT
User-agent: slrn/0.9.8.0 (Linux)

Dear People,

Consider the following small program, borrowed from
http://www.sgi.com/tech/stl/hash_map.html.

The current program compiles Ok with g++ 3.3 on Debian. My question is
why uncommenting the line

using __gnu_cxx::hash<const char*>;

and removing __gnu_gxx

from

hash_map<const char*, int, __gnu_gxx::hash<const char*>, eqstr> months;

does not work.

Please cc me; I'm not subscribed. Thanks.               Faheem.

********************************************************************
#include <ext/hash_map>
#include <iostream>
#include <cstring>
#include <string>

using std::cout;
using std::endl;
using std::strcmp;
using std::string;
using __gnu_cxx::hash_map;
//using __gnu_cxx::hash<const char*>;

struct eqstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) == 0;
  }
};

int main()
{
  hash_map<const char*, int, __gnu_cxx::hash<const char*>, eqstr> months;
  //hash_map<const char*, int, hash<const char*>, eqstr> months;

  months["january"] = 31;
  months["february"] = 28;
  months["march"] = 31;
  months["april"] = 30;
  months["may"] = 31;
  months["june"] = 30;
  months["july"] = 31;
  months["august"] = 31;
  months["september"] = 30;
  months["october"] = 31;
  months["november"] = 30;
  months["december"] = 31;
  
  cout << "september -> " << months["september"] << endl;
  cout << "april     -> " << months["april"] << endl;
  cout << "june      -> " << months["june"] << endl;
  cout << "november  -> " << months["november"] << endl;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]