std_hash.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/std_hash.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2018-2024 Antony Polukhin
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See
  9. // accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_VARIANT_DETAIL_STD_HASH_HPP
  12. #define BOOST_VARIANT_DETAIL_STD_HASH_HPP
  13. #include <boost/config.hpp>
  14. #ifdef BOOST_HAS_PRAGMA_ONCE
  15. # pragma once
  16. #endif
  17. #include <boost/variant/variant_fwd.hpp>
  18. #include <boost/variant/detail/hash_variant.hpp>
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // macro BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH
  21. //
  22. // Define this macro if you do not wish to have a std::hash specialization for
  23. // boost::variant.
  24. #if !defined(BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
  25. #include <functional> // for std::hash
  26. namespace std {
  27. template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
  28. struct hash<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) > > {
  29. std::size_t operator()(const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& val) const {
  30. return ::boost::hash_value(val);
  31. }
  32. };
  33. }
  34. #endif // #if !defined(BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
  35. #endif // BOOST_VARIANT_DETAIL_STD_HASH_HPP