Unordered associative containers (C++): Difference between revisions

Content deleted Content added
Replaced C style rubbish with proper intended C++ operation and simplified code. TODO: complex example for custom types.
Line 9:
It is closely related to <code>[[unordered_multimap]]</code> (available in the same header file), which is an implementation of [[multimap]] using hashing. It is also similar to <code>[[unordered_set]]</code> and <code>[[unordered_multiset]]</code>, implementations of the [[set (computer science)|set]] and [[multiset]] containers respectively and available in the <code><tr1/unordered_set></code> or <code><unordered_set></code> headers.
 
== UsageDescription ==
<source lang="cpp">
template<class Key,
Line 27:
; [Alloc] : a function which allocates new elements.
 
==ExampleSample with GNU C++Code==
===Basic Usage===
 
<source lang="cpp">
#include <iostream>
#include <cstringstring>
#include <unordered_map>
using namespace tr1std;
#include <cstring>
namespace std {
using namespace tr1;
}
 
 
struct eqstr{
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1,s2)==0;
}
};
 
int main()
{
std::unordered_map<const char*string, int, std::hash<const char*>, eqstr> months;
months["january"] = 31;
months["february"] = 28;
Line 59 ⟶ 50:
months["november"] = 30;
months["december"] = 31;
std::cout << "september -> " << months["september"] << std::endl;
std::cout << "april -> " << months["april"] << std::endl;
std::cout << "june december -> " << months["junedecember"] << std::endl;
std::cout << "novemberfebruary -> " << months["novemberfebruary"] << std::endl;
return 0;
}