| 1 | //----------------------------------------------------------------------------- |
|---|---|
| 2 | // boost variant/detail/hash_variant.hpp header file |
| 3 | // See http://www.boost.org for updates, documentation, and revision history. |
| 4 | //----------------------------------------------------------------------------- |
| 5 | // |
| 6 | // Copyright (c) 2011-2023 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 | |
| 12 | |
| 13 | #ifndef BOOST_HASH_VARIANT_FUNCTION_HPP |
| 14 | #define BOOST_HASH_VARIANT_FUNCTION_HPP |
| 15 | |
| 16 | #if defined(_MSC_VER) |
| 17 | # pragma once |
| 18 | #endif |
| 19 | |
| 20 | #include <boost/variant/variant_fwd.hpp> |
| 21 | #include <boost/variant/static_visitor.hpp> |
| 22 | #include <boost/variant/apply_visitor.hpp> |
| 23 | #include <boost/functional/hash_fwd.hpp> |
| 24 | |
| 25 | namespace boost { |
| 26 | |
| 27 | namespace detail { namespace variant { |
| 28 | struct variant_hasher: public boost::static_visitor<std::size_t> { |
| 29 | template <class T> |
| 30 | std::size_t operator()(T const& val) const { |
| 31 | boost::hash<T> hasher; |
| 32 | return hasher(val); |
| 33 | } |
| 34 | }; |
| 35 | }} |
| 36 | |
| 37 | template < BOOST_VARIANT_ENUM_PARAMS(typename T) > |
| 38 | std::size_t hash_value(variant< BOOST_VARIANT_ENUM_PARAMS(T) > const& val) { |
| 39 | std::size_t seed = boost::apply_visitor(detail::variant::variant_hasher(), val); |
| 40 | hash_combine(seed, val.which()); |
| 41 | return seed; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | #endif |
| 46 | |
| 47 |