1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___OPTIONAL_HASH_H
11#define _LIBCPP___OPTIONAL_HASH_H
12
13#include <__config>
14#include <__cstddef/size_t.h>
15#include <__functional/hash.h>
16#include <__fwd/optional.h>
17#include <__type_traits/remove_const.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_PUSH_MACROS
24#include <__undef_macros>
25
26#if _LIBCPP_STD_VER >= 17
27
28_LIBCPP_BEGIN_NAMESPACE_STD
29
30template <class _Tp>
31struct hash< __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>> > {
32# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
33 _LIBCPP_DEPRECATED_IN_CXX17 typedef optional<_Tp> argument_type;
34 _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
35# endif
36
37 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t operator()(const optional<_Tp>& __opt) const {
38 return static_cast<bool>(__opt) ? hash<remove_const_t<_Tp>>()(*__opt) : 0;
39 }
40};
41
42_LIBCPP_END_NAMESPACE_STD
43
44#endif // _LIBCPP_STD_VER >= 17
45
46_LIBCPP_POP_MACROS
47#endif // _LIBCPP___OPTIONAL_HASH_H
48