boost_has_hash.ipp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // (C) Copyright John Maddock 2001.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_HAS_HASH
  7. // TITLE: <hashset> and <hashmap>
  8. // DESCRIPTION: The C++ implementation provides the (SGI) hash_set
  9. // or hash_map classes.
  10. #if defined(__GLIBCXX__) || (defined(__GLIBCPP__) && __GLIBCPP__>=20020514) // GCC >= 3.1.0
  11. # ifdef BOOST_NO_CXX11_STD_UNORDERED
  12. # define BOOST_STD_EXTENSION_NAMESPACE __gnu_cxx
  13. # define _BACKWARD_BACKWARD_WARNING_H 1 /* turn off warnings from the headers below */
  14. # include <ext/hash_set>
  15. # include <ext/hash_map>
  16. # else
  17. // If we have BOOST_NO_CXX11_STD_UNORDERED *not* defined, then we must
  18. // not include the <ext/*> headers as they clash with the C++0x
  19. // headers. ie in any given translation unit we can include one
  20. // or the other, but not both.
  21. # define DISABLE_BOOST_HAS_HASH_TEST
  22. # endif
  23. #else
  24. #include <hash_set>
  25. #include <hash_map>
  26. #endif
  27. #ifndef BOOST_STD_EXTENSION_NAMESPACE
  28. #define BOOST_STD_EXTENSION_NAMESPACE std
  29. #endif
  30. namespace boost_has_hash{
  31. #ifndef DISABLE_BOOST_HAS_HASH_TEST
  32. template <class Key, class Eq, class Hash, class Alloc>
  33. void foo(const BOOST_STD_EXTENSION_NAMESPACE::hash_set<Key,Eq,Hash,Alloc>& )
  34. {
  35. }
  36. template <class Key, class T, class Eq, class Hash, class Alloc>
  37. void foo(const BOOST_STD_EXTENSION_NAMESPACE::hash_map<Key,T,Eq,Hash,Alloc>& )
  38. {
  39. }
  40. #endif
  41. int test()
  42. {
  43. #ifndef DISABLE_BOOST_HAS_HASH_TEST
  44. BOOST_STD_EXTENSION_NAMESPACE::hash_set<int> hs;
  45. foo(hs);
  46. BOOST_STD_EXTENSION_NAMESPACE::hash_map<int, long> hm;
  47. foo(hm);
  48. #endif
  49. return 0;
  50. }
  51. }