============ VC2005 ================
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
struct Key{
int i;
};
namespace std {
template <> struct less<::Key>
: public binary_function<::Key, ::Key, bool>
{
bool operator()(const ::Key& _Left, const ::Key& _Right) const
{ // apply operator< to operands
return (_Left.i < _Right.i);
}
};
}
namespace stdext {
template <> size_t hash_value
return hash_value
}
}
int _tmain(int argc, _TCHAR* argv[])
{
stdext::hash_map
Key k;
k.i = 1;
testmap[k] = std::string("hello, world");
testmap[k] = std::string("hello, again");
std::cout << "size of map: " << testmap.size() << std::endl;
return 0;
}
============GCC + STLPort ===========
struct Key {
...
};
namespace std {
template <> struct hash
size_t operator()(const Key &key) const {
...
};
}
}
int main()
{
...
}