| 1 | // Copyright (C) 2022 Andrzej Krzemienski. |
| 2 | // |
| 3 | // Use, modification, and distribution is subject to the Boost Software |
| 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | // http://www.boost.org/LICENSE_1_0.txt) |
| 6 | // |
| 7 | // See http://www.boost.org/libs/optional for documentation. |
| 8 | // |
| 9 | // You are welcome to contact the author at: |
| 10 | // akrzemi1@gmail.com |
| 11 | |
| 12 | #ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_HASH_AJK_20MAY2022_HPP |
| 13 | #define BOOST_OPTIONAL_DETAIL_OPTIONAL_HASH_AJK_20MAY2022_HPP |
| 14 | |
| 15 | #include <boost/optional/optional_fwd.hpp> |
| 16 | #include <boost/config.hpp> |
| 17 | |
| 18 | #if !defined(BOOST_OPTIONAL_CONFIG_DO_NOT_SPECIALIZE_STD_HASH) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) |
| 19 | |
| 20 | #include <functional> |
| 21 | |
| 22 | namespace std |
| 23 | { |
| 24 | template <typename T> |
| 25 | struct hash<boost::optional<T> > |
| 26 | { |
| 27 | typedef std::size_t result_type; |
| 28 | typedef boost::optional<T> argument_type; |
| 29 | |
| 30 | BOOST_CONSTEXPR result_type operator()(const argument_type& arg) const { |
| 31 | return arg ? std::hash<T>()(*arg) : result_type(); |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | template <typename T> |
| 36 | struct hash<boost::optional<T&> > |
| 37 | { |
| 38 | typedef std::size_t result_type; |
| 39 | typedef boost::optional<T&> argument_type; |
| 40 | |
| 41 | BOOST_CONSTEXPR result_type operator()(const argument_type& arg) const { |
| 42 | return arg ? std::hash<T>()(*arg) : result_type(); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | #endif // !defined(BOOST_OPTIONAL_CONFIG_DO_NOT_SPECIALIZE_STD_HASH) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) |
| 48 | |
| 49 | #endif // header guard |
| 50 | |