From 64deb08509bf9682e7d3b8141399c5603edb2df2 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 2 Sep 2009 16:43:58 -0700 Subject: Provide backward-compatible unordered_map/set We were defining our own stap_map with a ::type to let us use typedefs to use the new unordered_map if available, or hash_map otherwise. Since unordered_map is the future direction, I'm changing our code to use that directly. The backward-compatible version is a #define to hash_map, which has a compatible interface. While I'm at it, let's also define unordered_multimap, unordered_set, and unordered_multiset. * unordered.h: New. * dwflpp.h (stap_map): Removed. (cache typedefs): Use the unordered name now. --- unordered.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 unordered.h (limited to 'unordered.h') diff --git a/unordered.h b/unordered.h new file mode 100644 index 00000000..6204dbfb --- /dev/null +++ b/unordered.h @@ -0,0 +1,56 @@ +// backward-compatible unordered containers +// Copyright (C) 2009 Red Hat Inc. +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + +#ifndef UNORDERED_H +#define UNORDERED_H + +#include "config.h" + +#if 0 // uncomment to force the old mode +#undef HAVE_TR1_UNORDERED_MAP +#define _BACKWARD_BACKWARD_WARNING_H 1 // defeat deprecation warning +#endif + +#ifdef HAVE_TR1_UNORDERED_MAP + +#include +using std::tr1::unordered_map; +using std::tr1::unordered_multimap; + +#include +using std::tr1::unordered_set; +using std::tr1::unordered_multiset; + +#else + +#include +#define unordered_map __gnu_cxx::hash_map +#define unordered_multimap __gnu_cxx::hash_multimap + +#include +#define unordered_set __gnu_cxx::hash_set +#define unordered_multiset __gnu_cxx::hash_multiset + +// Hack in common hash functions for strings and raw pointers +namespace __gnu_cxx +{ + template struct hash { + size_t operator() (T* p) const + { hash h; return h(reinterpret_cast(p)); } + }; + template<> struct hash { + size_t operator() (std::string const& s) const + { hash h; return h(s.c_str()); } + }; +} + +#endif + +#endif // UNORDERED_H + +/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- cgit