1// Copyright (C) 2022 Christian Mazakas
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef BOOST_UNORDERED_DETAIL_TYPE_TRAITS_HPP
7#define BOOST_UNORDERED_DETAIL_TYPE_TRAITS_HPP
8
9#include <boost/config.hpp>
10#if defined(BOOST_HAS_PRAGMA_ONCE)
11#pragma once
12#endif
13
14#include <boost/type_traits/integral_constant.hpp>
15#include <boost/type_traits/is_convertible.hpp>
16#include <boost/type_traits/make_void.hpp>
17#include <boost/type_traits/type_identity.hpp>
18
19#if !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
20#include <boost/type_traits/enable_if.hpp>
21#include <boost/type_traits/is_integral.hpp>
22#include <boost/type_traits/remove_const.hpp>
23
24#include <iterator>
25#include <utility>
26#endif
27
28// BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
29
30#if !defined(BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES)
31#if !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
32#define BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES 1
33#endif
34#endif
35
36#if !defined(BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES)
37#define BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES 0
38#endif
39
40namespace boost {
41 namespace unordered {
42 namespace detail {
43 ////////////////////////////////////////////////////////////////////////////
44 // Type checkers used for the transparent member functions added by C++20
45 // and up
46
47 template <class, class = void>
48 struct is_transparent : public boost::false_type
49 {
50 };
51
52 template <class T>
53 struct is_transparent<T,
54 typename boost::make_void<typename T::is_transparent>::type>
55 : public boost::true_type
56 {
57 };
58
59 template <class, class Hash, class KeyEqual> struct are_transparent
60 {
61 static bool const value =
62 is_transparent<Hash>::value && is_transparent<KeyEqual>::value;
63 };
64
65 template <class Key, class UnorderedMap> struct transparent_non_iterable
66 {
67 typedef typename UnorderedMap::hasher hash;
68 typedef typename UnorderedMap::key_equal key_equal;
69 typedef typename UnorderedMap::iterator iterator;
70 typedef typename UnorderedMap::const_iterator const_iterator;
71
72 static bool const value =
73 are_transparent<Key, hash, key_equal>::value &&
74 !boost::is_convertible<Key, iterator>::value &&
75 !boost::is_convertible<Key, const_iterator>::value;
76 };
77
78#if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
79 // https://eel.is/c++draft/container.requirements#container.alloc.reqmts-34
80 // https://eel.is/c++draft/container.requirements#unord.req.general-243
81
82 template <class InputIterator>
83 constexpr bool const is_input_iterator_v =
84 !boost::is_integral<InputIterator>::value;
85
86 template <class A, class = void> struct is_allocator
87 {
88 constexpr static bool const value = false;
89 };
90
91 template <class A>
92 struct is_allocator<A,
93 boost::void_t<typename A::value_type,
94 decltype(std::declval<A&>().allocate(std::size_t{}))> >
95 {
96 constexpr static bool const value = true;
97 };
98
99 template <class A>
100 constexpr bool const is_allocator_v = is_allocator<A>::value;
101
102 template <class H>
103 constexpr bool const is_hash_v =
104 !boost::is_integral<H>::value && !is_allocator_v<H>;
105
106 template <class P> constexpr bool const is_pred_v = !is_allocator_v<P>;
107
108 template <typename T>
109 using iter_key_t =
110 typename std::iterator_traits<T>::value_type::first_type;
111 template <typename T>
112 using iter_val_t =
113 typename std::iterator_traits<T>::value_type::second_type;
114 template <typename T>
115 using iter_to_alloc_t =
116 typename std::pair<iter_key_t<T> const, iter_val_t<T> >;
117#endif
118 } // namespace detail
119 } // namespace unordered
120} // namespace boost
121
122#endif // BOOST_UNORDERED_DETAIL_TYPE_TRAITS_HPP
123

source code of include/boost/unordered/detail/type_traits.hpp