grpc 1.26.0 → 1.27.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1654 -1519
  3. data/etc/roots.pem +44 -0
  4. data/include/grpc/grpc_security.h +37 -15
  5. data/include/grpc/grpc_security_constants.h +27 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +14 -0
  7. data/include/grpc/impl/codegen/port_platform.h +1 -1
  8. data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
  9. data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
  10. data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
  11. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
  24. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  25. data/src/core/ext/filters/client_channel/server_address.h +3 -10
  26. data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
  27. data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
  28. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
  29. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
  30. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
  31. data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
  32. data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
  33. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
  34. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
  35. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  36. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
  37. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
  38. data/src/core/lib/channel/channelz.h +11 -1
  39. data/src/core/lib/gpr/time_precise.cc +1 -1
  40. data/src/core/lib/gprpp/optional.h +26 -0
  41. data/src/core/lib/gprpp/string_view.h +14 -10
  42. data/src/core/lib/iomgr/executor.cc +1 -1
  43. data/src/core/lib/iomgr/fork_posix.cc +4 -0
  44. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
  45. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
  46. data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
  47. data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
  48. data/src/core/lib/iomgr/tcp_custom.h +3 -0
  49. data/src/core/lib/iomgr/tcp_posix.cc +607 -56
  50. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
  51. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
  52. data/src/core/lib/json/json.h +11 -1
  53. data/src/core/lib/json/json_reader.cc +206 -28
  54. data/src/core/lib/json/json_writer.cc +111 -24
  55. data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
  56. data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
  57. data/src/core/lib/security/credentials/credentials.h +10 -1
  58. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
  59. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  60. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
  61. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
  62. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
  63. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
  64. data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
  65. data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
  66. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
  67. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
  68. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
  69. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
  70. data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
  71. data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
  72. data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
  73. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
  74. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
  75. data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
  76. data/src/core/lib/surface/completion_queue.cc +22 -1
  77. data/src/core/lib/surface/version.cc +1 -1
  78. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
  79. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  80. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
  81. data/src/core/tsi/fake_transport_security.cc +7 -3
  82. data/src/core/tsi/fake_transport_security.h +2 -0
  83. data/src/core/tsi/ssl_transport_security.cc +144 -8
  84. data/src/core/tsi/ssl_transport_security.h +15 -1
  85. data/src/core/tsi/transport_security.cc +13 -0
  86. data/src/core/tsi/transport_security_grpc.cc +2 -2
  87. data/src/core/tsi/transport_security_grpc.h +2 -2
  88. data/src/core/tsi/transport_security_interface.h +12 -0
  89. data/src/ruby/bin/math_pb.rb +5 -5
  90. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
  91. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  92. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  93. data/src/ruby/lib/grpc/version.rb +1 -1
  94. data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
  95. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
  96. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
  97. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
  98. data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
  99. data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
  100. data/third_party/abseil-cpp/absl/base/casts.h +184 -0
  101. data/third_party/abseil-cpp/absl/base/config.h +622 -0
  102. data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
  103. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
  104. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
  105. data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
  106. data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
  107. data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
  108. data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
  109. data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
  110. data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
  111. data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
  112. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
  113. data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
  114. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
  115. data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
  116. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
  117. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
  118. data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
  119. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
  120. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
  121. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
  122. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
  123. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
  124. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
  125. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
  126. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
  127. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
  128. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
  129. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
  130. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
  131. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
  132. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
  133. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
  134. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
  135. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
  136. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
  137. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
  138. data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
  139. data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
  140. data/third_party/abseil-cpp/absl/base/macros.h +220 -0
  141. data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
  142. data/third_party/abseil-cpp/absl/base/options.h +214 -0
  143. data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
  144. data/third_party/abseil-cpp/absl/base/port.h +26 -0
  145. data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
  146. data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
  147. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
  148. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
  149. data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
  150. data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
  151. data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
  152. data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
  153. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
  154. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
  155. data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
  156. data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
  157. data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
  158. data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
  159. data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
  160. data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
  161. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
  162. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
  163. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
  164. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
  165. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
  166. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
  167. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
  168. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
  169. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
  170. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
  171. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
  172. data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
  173. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
  174. data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
  175. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
  176. data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
  177. data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
  178. data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
  179. data/third_party/abseil-cpp/absl/strings/match.h +90 -0
  180. data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
  181. data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
  182. data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
  183. data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
  184. data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
  185. data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
  186. data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
  187. data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
  188. data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
  189. data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
  190. data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
  191. data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
  192. data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
  193. data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
  194. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
  195. data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
  196. data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
  197. data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
  198. data/third_party/abseil-cpp/absl/types/optional.h +776 -0
  199. data/third_party/abseil-cpp/absl/types/span.h +713 -0
  200. data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
  201. data/third_party/upb/upb/decode.c +4 -0
  202. data/third_party/upb/upb/port.c +0 -1
  203. data/third_party/upb/upb/port_def.inc +1 -3
  204. data/third_party/upb/upb/table.c +2 -1
  205. metadata +147 -43
  206. data/src/core/lib/json/json_common.h +0 -34
  207. data/src/core/lib/json/json_reader.h +0 -146
  208. data/src/core/lib/json/json_string.cc +0 -367
  209. data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,759 @@
1
+ //
2
+ // Copyright 2017 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+ // -----------------------------------------------------------------------------
17
+ // type_traits.h
18
+ // -----------------------------------------------------------------------------
19
+ //
20
+ // This file contains C++11-compatible versions of standard <type_traits> API
21
+ // functions for determining the characteristics of types. Such traits can
22
+ // support type inference, classification, and transformation, as well as
23
+ // make it easier to write templates based on generic type behavior.
24
+ //
25
+ // See https://en.cppreference.com/w/cpp/header/type_traits
26
+ //
27
+ // WARNING: use of many of the constructs in this header will count as "complex
28
+ // template metaprogramming", so before proceeding, please carefully consider
29
+ // https://google.github.io/styleguide/cppguide.html#Template_metaprogramming
30
+ //
31
+ // WARNING: using template metaprogramming to detect or depend on API
32
+ // features is brittle and not guaranteed. Neither the standard library nor
33
+ // Abseil provides any guarantee that APIs are stable in the face of template
34
+ // metaprogramming. Use with caution.
35
+ #ifndef ABSL_META_TYPE_TRAITS_H_
36
+ #define ABSL_META_TYPE_TRAITS_H_
37
+
38
+ #include <stddef.h>
39
+ #include <functional>
40
+ #include <type_traits>
41
+
42
+ #include "absl/base/config.h"
43
+
44
+ // MSVC constructibility traits do not detect destructor properties and so our
45
+ // implementations should not use them as a source-of-truth.
46
+ #if defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__)
47
+ #define ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION 1
48
+ #endif
49
+
50
+ namespace absl {
51
+ ABSL_NAMESPACE_BEGIN
52
+
53
+ // Defined and documented later on in this file.
54
+ template <typename T>
55
+ struct is_trivially_destructible;
56
+
57
+ // Defined and documented later on in this file.
58
+ template <typename T>
59
+ struct is_trivially_move_assignable;
60
+
61
+ namespace type_traits_internal {
62
+
63
+ // Silence MSVC warnings about the destructor being defined as deleted.
64
+ #if defined(_MSC_VER) && !defined(__GNUC__)
65
+ #pragma warning(push)
66
+ #pragma warning(disable : 4624)
67
+ #endif // defined(_MSC_VER) && !defined(__GNUC__)
68
+
69
+ template <class T>
70
+ union SingleMemberUnion {
71
+ T t;
72
+ };
73
+
74
+ // Restore the state of the destructor warning that was silenced above.
75
+ #if defined(_MSC_VER) && !defined(__GNUC__)
76
+ #pragma warning(pop)
77
+ #endif // defined(_MSC_VER) && !defined(__GNUC__)
78
+
79
+ template <class T>
80
+ struct IsTriviallyMoveConstructibleObject
81
+ : std::integral_constant<
82
+ bool, std::is_move_constructible<
83
+ type_traits_internal::SingleMemberUnion<T>>::value &&
84
+ absl::is_trivially_destructible<T>::value> {};
85
+
86
+ template <class T>
87
+ struct IsTriviallyCopyConstructibleObject
88
+ : std::integral_constant<
89
+ bool, std::is_copy_constructible<
90
+ type_traits_internal::SingleMemberUnion<T>>::value &&
91
+ absl::is_trivially_destructible<T>::value> {};
92
+
93
+ template <class T>
94
+ struct IsTriviallyMoveAssignableReference : std::false_type {};
95
+
96
+ template <class T>
97
+ struct IsTriviallyMoveAssignableReference<T&>
98
+ : absl::is_trivially_move_assignable<T>::type {};
99
+
100
+ template <class T>
101
+ struct IsTriviallyMoveAssignableReference<T&&>
102
+ : absl::is_trivially_move_assignable<T>::type {};
103
+
104
+ template <typename... Ts>
105
+ struct VoidTImpl {
106
+ using type = void;
107
+ };
108
+
109
+ // This trick to retrieve a default alignment is necessary for our
110
+ // implementation of aligned_storage_t to be consistent with any implementation
111
+ // of std::aligned_storage.
112
+ template <size_t Len, typename T = std::aligned_storage<Len>>
113
+ struct default_alignment_of_aligned_storage;
114
+
115
+ template <size_t Len, size_t Align>
116
+ struct default_alignment_of_aligned_storage<Len,
117
+ std::aligned_storage<Len, Align>> {
118
+ static constexpr size_t value = Align;
119
+ };
120
+
121
+ ////////////////////////////////
122
+ // Library Fundamentals V2 TS //
123
+ ////////////////////////////////
124
+
125
+ // NOTE: The `is_detected` family of templates here differ from the library
126
+ // fundamentals specification in that for library fundamentals, `Op<Args...>` is
127
+ // evaluated as soon as the type `is_detected<Op, Args...>` undergoes
128
+ // substitution, regardless of whether or not the `::value` is accessed. That
129
+ // is inconsistent with all other standard traits and prevents lazy evaluation
130
+ // in larger contexts (such as if the `is_detected` check is a trailing argument
131
+ // of a `conjunction`. This implementation opts to instead be lazy in the same
132
+ // way that the standard traits are (this "defect" of the detection idiom
133
+ // specifications has been reported).
134
+
135
+ template <class Enabler, template <class...> class Op, class... Args>
136
+ struct is_detected_impl {
137
+ using type = std::false_type;
138
+ };
139
+
140
+ template <template <class...> class Op, class... Args>
141
+ struct is_detected_impl<typename VoidTImpl<Op<Args...>>::type, Op, Args...> {
142
+ using type = std::true_type;
143
+ };
144
+
145
+ template <template <class...> class Op, class... Args>
146
+ struct is_detected : is_detected_impl<void, Op, Args...>::type {};
147
+
148
+ template <class Enabler, class To, template <class...> class Op, class... Args>
149
+ struct is_detected_convertible_impl {
150
+ using type = std::false_type;
151
+ };
152
+
153
+ template <class To, template <class...> class Op, class... Args>
154
+ struct is_detected_convertible_impl<
155
+ typename std::enable_if<std::is_convertible<Op<Args...>, To>::value>::type,
156
+ To, Op, Args...> {
157
+ using type = std::true_type;
158
+ };
159
+
160
+ template <class To, template <class...> class Op, class... Args>
161
+ struct is_detected_convertible
162
+ : is_detected_convertible_impl<void, To, Op, Args...>::type {};
163
+
164
+ template <typename T>
165
+ using IsCopyAssignableImpl =
166
+ decltype(std::declval<T&>() = std::declval<const T&>());
167
+
168
+ template <typename T>
169
+ using IsMoveAssignableImpl = decltype(std::declval<T&>() = std::declval<T&&>());
170
+
171
+ } // namespace type_traits_internal
172
+
173
+ // MSVC 19.20 has a regression that causes our workarounds to fail, but their
174
+ // std forms now appear to be compliant.
175
+ #if defined(_MSC_VER) && !defined(__clang__) && (_MSC_VER >= 1920)
176
+
177
+ template <typename T>
178
+ using is_copy_assignable = std::is_copy_assignable<T>;
179
+
180
+ template <typename T>
181
+ using is_move_assignable = std::is_move_assignable<T>;
182
+
183
+ #else
184
+
185
+ template <typename T>
186
+ struct is_copy_assignable : type_traits_internal::is_detected<
187
+ type_traits_internal::IsCopyAssignableImpl, T> {
188
+ };
189
+
190
+ template <typename T>
191
+ struct is_move_assignable : type_traits_internal::is_detected<
192
+ type_traits_internal::IsMoveAssignableImpl, T> {
193
+ };
194
+
195
+ #endif
196
+
197
+ // void_t()
198
+ //
199
+ // Ignores the type of any its arguments and returns `void`. In general, this
200
+ // metafunction allows you to create a general case that maps to `void` while
201
+ // allowing specializations that map to specific types.
202
+ //
203
+ // This metafunction is designed to be a drop-in replacement for the C++17
204
+ // `std::void_t` metafunction.
205
+ //
206
+ // NOTE: `absl::void_t` does not use the standard-specified implementation so
207
+ // that it can remain compatible with gcc < 5.1. This can introduce slightly
208
+ // different behavior, such as when ordering partial specializations.
209
+ template <typename... Ts>
210
+ using void_t = typename type_traits_internal::VoidTImpl<Ts...>::type;
211
+
212
+ // conjunction
213
+ //
214
+ // Performs a compile-time logical AND operation on the passed types (which
215
+ // must have `::value` members convertible to `bool`. Short-circuits if it
216
+ // encounters any `false` members (and does not compare the `::value` members
217
+ // of any remaining arguments).
218
+ //
219
+ // This metafunction is designed to be a drop-in replacement for the C++17
220
+ // `std::conjunction` metafunction.
221
+ template <typename... Ts>
222
+ struct conjunction;
223
+
224
+ template <typename T, typename... Ts>
225
+ struct conjunction<T, Ts...>
226
+ : std::conditional<T::value, conjunction<Ts...>, T>::type {};
227
+
228
+ template <typename T>
229
+ struct conjunction<T> : T {};
230
+
231
+ template <>
232
+ struct conjunction<> : std::true_type {};
233
+
234
+ // disjunction
235
+ //
236
+ // Performs a compile-time logical OR operation on the passed types (which
237
+ // must have `::value` members convertible to `bool`. Short-circuits if it
238
+ // encounters any `true` members (and does not compare the `::value` members
239
+ // of any remaining arguments).
240
+ //
241
+ // This metafunction is designed to be a drop-in replacement for the C++17
242
+ // `std::disjunction` metafunction.
243
+ template <typename... Ts>
244
+ struct disjunction;
245
+
246
+ template <typename T, typename... Ts>
247
+ struct disjunction<T, Ts...> :
248
+ std::conditional<T::value, T, disjunction<Ts...>>::type {};
249
+
250
+ template <typename T>
251
+ struct disjunction<T> : T {};
252
+
253
+ template <>
254
+ struct disjunction<> : std::false_type {};
255
+
256
+ // negation
257
+ //
258
+ // Performs a compile-time logical NOT operation on the passed type (which
259
+ // must have `::value` members convertible to `bool`.
260
+ //
261
+ // This metafunction is designed to be a drop-in replacement for the C++17
262
+ // `std::negation` metafunction.
263
+ template <typename T>
264
+ struct negation : std::integral_constant<bool, !T::value> {};
265
+
266
+ // is_function()
267
+ //
268
+ // Determines whether the passed type `T` is a function type.
269
+ //
270
+ // This metafunction is designed to be a drop-in replacement for the C++11
271
+ // `std::is_function()` metafunction for platforms that have incomplete C++11
272
+ // support (such as libstdc++ 4.x).
273
+ //
274
+ // This metafunction works because appending `const` to a type does nothing to
275
+ // function types and reference types (and forms a const-qualified type
276
+ // otherwise).
277
+ template <typename T>
278
+ struct is_function
279
+ : std::integral_constant<
280
+ bool, !(std::is_reference<T>::value ||
281
+ std::is_const<typename std::add_const<T>::type>::value)> {};
282
+
283
+ // is_trivially_destructible()
284
+ //
285
+ // Determines whether the passed type `T` is trivially destructible.
286
+ //
287
+ // This metafunction is designed to be a drop-in replacement for the C++11
288
+ // `std::is_trivially_destructible()` metafunction for platforms that have
289
+ // incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
290
+ // fully support C++11, we check whether this yields the same result as the std
291
+ // implementation.
292
+ //
293
+ // NOTE: the extensions (__has_trivial_xxx) are implemented in gcc (version >=
294
+ // 4.3) and clang. Since we are supporting libstdc++ > 4.7, they should always
295
+ // be present. These extensions are documented at
296
+ // https://gcc.gnu.org/onlinedocs/gcc/Type-Traits.html#Type-Traits.
297
+ template <typename T>
298
+ struct is_trivially_destructible
299
+ : std::integral_constant<bool, __has_trivial_destructor(T) &&
300
+ std::is_destructible<T>::value> {
301
+ #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
302
+ private:
303
+ static constexpr bool compliant = std::is_trivially_destructible<T>::value ==
304
+ is_trivially_destructible::value;
305
+ static_assert(compliant || std::is_trivially_destructible<T>::value,
306
+ "Not compliant with std::is_trivially_destructible; "
307
+ "Standard: false, Implementation: true");
308
+ static_assert(compliant || !std::is_trivially_destructible<T>::value,
309
+ "Not compliant with std::is_trivially_destructible; "
310
+ "Standard: true, Implementation: false");
311
+ #endif // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
312
+ };
313
+
314
+ // is_trivially_default_constructible()
315
+ //
316
+ // Determines whether the passed type `T` is trivially default constructible.
317
+ //
318
+ // This metafunction is designed to be a drop-in replacement for the C++11
319
+ // `std::is_trivially_default_constructible()` metafunction for platforms that
320
+ // have incomplete C++11 support (such as libstdc++ 4.x). On any platforms that
321
+ // do fully support C++11, we check whether this yields the same result as the
322
+ // std implementation.
323
+ //
324
+ // NOTE: according to the C++ standard, Section: 20.15.4.3 [meta.unary.prop]
325
+ // "The predicate condition for a template specialization is_constructible<T,
326
+ // Args...> shall be satisfied if and only if the following variable
327
+ // definition would be well-formed for some invented variable t:
328
+ //
329
+ // T t(declval<Args>()...);
330
+ //
331
+ // is_trivially_constructible<T, Args...> additionally requires that the
332
+ // variable definition does not call any operation that is not trivial.
333
+ // For the purposes of this check, the call to std::declval is considered
334
+ // trivial."
335
+ //
336
+ // Notes from https://en.cppreference.com/w/cpp/types/is_constructible:
337
+ // In many implementations, is_nothrow_constructible also checks if the
338
+ // destructor throws because it is effectively noexcept(T(arg)). Same
339
+ // applies to is_trivially_constructible, which, in these implementations, also
340
+ // requires that the destructor is trivial.
341
+ // GCC bug 51452: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51452
342
+ // LWG issue 2116: http://cplusplus.github.io/LWG/lwg-active.html#2116.
343
+ //
344
+ // "T obj();" need to be well-formed and not call any nontrivial operation.
345
+ // Nontrivially destructible types will cause the expression to be nontrivial.
346
+ template <typename T>
347
+ struct is_trivially_default_constructible
348
+ : std::integral_constant<bool, __has_trivial_constructor(T) &&
349
+ std::is_default_constructible<T>::value &&
350
+ is_trivially_destructible<T>::value> {
351
+ #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
352
+ !defined( \
353
+ ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
354
+ private:
355
+ static constexpr bool compliant =
356
+ std::is_trivially_default_constructible<T>::value ==
357
+ is_trivially_default_constructible::value;
358
+ static_assert(compliant || std::is_trivially_default_constructible<T>::value,
359
+ "Not compliant with std::is_trivially_default_constructible; "
360
+ "Standard: false, Implementation: true");
361
+ static_assert(compliant || !std::is_trivially_default_constructible<T>::value,
362
+ "Not compliant with std::is_trivially_default_constructible; "
363
+ "Standard: true, Implementation: false");
364
+ #endif // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
365
+ };
366
+
367
+ // is_trivially_move_constructible()
368
+ //
369
+ // Determines whether the passed type `T` is trivially move constructible.
370
+ //
371
+ // This metafunction is designed to be a drop-in replacement for the C++11
372
+ // `std::is_trivially_move_constructible()` metafunction for platforms that have
373
+ // incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
374
+ // fully support C++11, we check whether this yields the same result as the std
375
+ // implementation.
376
+ //
377
+ // NOTE: `T obj(declval<T>());` needs to be well-formed and not call any
378
+ // nontrivial operation. Nontrivially destructible types will cause the
379
+ // expression to be nontrivial.
380
+ template <typename T>
381
+ struct is_trivially_move_constructible
382
+ : std::conditional<
383
+ std::is_object<T>::value && !std::is_array<T>::value,
384
+ type_traits_internal::IsTriviallyMoveConstructibleObject<T>,
385
+ std::is_reference<T>>::type::type {
386
+ #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
387
+ !defined( \
388
+ ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
389
+ private:
390
+ static constexpr bool compliant =
391
+ std::is_trivially_move_constructible<T>::value ==
392
+ is_trivially_move_constructible::value;
393
+ static_assert(compliant || std::is_trivially_move_constructible<T>::value,
394
+ "Not compliant with std::is_trivially_move_constructible; "
395
+ "Standard: false, Implementation: true");
396
+ static_assert(compliant || !std::is_trivially_move_constructible<T>::value,
397
+ "Not compliant with std::is_trivially_move_constructible; "
398
+ "Standard: true, Implementation: false");
399
+ #endif // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
400
+ };
401
+
402
+ // is_trivially_copy_constructible()
403
+ //
404
+ // Determines whether the passed type `T` is trivially copy constructible.
405
+ //
406
+ // This metafunction is designed to be a drop-in replacement for the C++11
407
+ // `std::is_trivially_copy_constructible()` metafunction for platforms that have
408
+ // incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
409
+ // fully support C++11, we check whether this yields the same result as the std
410
+ // implementation.
411
+ //
412
+ // NOTE: `T obj(declval<const T&>());` needs to be well-formed and not call any
413
+ // nontrivial operation. Nontrivially destructible types will cause the
414
+ // expression to be nontrivial.
415
+ template <typename T>
416
+ struct is_trivially_copy_constructible
417
+ : std::conditional<
418
+ std::is_object<T>::value && !std::is_array<T>::value,
419
+ type_traits_internal::IsTriviallyCopyConstructibleObject<T>,
420
+ std::is_lvalue_reference<T>>::type::type {
421
+ #if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \
422
+ !defined( \
423
+ ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION)
424
+ private:
425
+ static constexpr bool compliant =
426
+ std::is_trivially_copy_constructible<T>::value ==
427
+ is_trivially_copy_constructible::value;
428
+ static_assert(compliant || std::is_trivially_copy_constructible<T>::value,
429
+ "Not compliant with std::is_trivially_copy_constructible; "
430
+ "Standard: false, Implementation: true");
431
+ static_assert(compliant || !std::is_trivially_copy_constructible<T>::value,
432
+ "Not compliant with std::is_trivially_copy_constructible; "
433
+ "Standard: true, Implementation: false");
434
+ #endif // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
435
+ };
436
+
437
+ // is_trivially_move_assignable()
438
+ //
439
+ // Determines whether the passed type `T` is trivially move assignable.
440
+ //
441
+ // This metafunction is designed to be a drop-in replacement for the C++11
442
+ // `std::is_trivially_move_assignable()` metafunction for platforms that have
443
+ // incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
444
+ // fully support C++11, we check whether this yields the same result as the std
445
+ // implementation.
446
+ //
447
+ // NOTE: `is_assignable<T, U>::value` is `true` if the expression
448
+ // `declval<T>() = declval<U>()` is well-formed when treated as an unevaluated
449
+ // operand. `is_trivially_assignable<T, U>` requires the assignment to call no
450
+ // operation that is not trivial. `is_trivially_copy_assignable<T>` is simply
451
+ // `is_trivially_assignable<T&, T>`.
452
+ template <typename T>
453
+ struct is_trivially_move_assignable
454
+ : std::conditional<
455
+ std::is_object<T>::value && !std::is_array<T>::value &&
456
+ std::is_move_assignable<T>::value,
457
+ std::is_move_assignable<type_traits_internal::SingleMemberUnion<T>>,
458
+ type_traits_internal::IsTriviallyMoveAssignableReference<T>>::type::
459
+ type {
460
+ #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
461
+ private:
462
+ static constexpr bool compliant =
463
+ std::is_trivially_move_assignable<T>::value ==
464
+ is_trivially_move_assignable::value;
465
+ static_assert(compliant || std::is_trivially_move_assignable<T>::value,
466
+ "Not compliant with std::is_trivially_move_assignable; "
467
+ "Standard: false, Implementation: true");
468
+ static_assert(compliant || !std::is_trivially_move_assignable<T>::value,
469
+ "Not compliant with std::is_trivially_move_assignable; "
470
+ "Standard: true, Implementation: false");
471
+ #endif // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
472
+ };
473
+
474
+ // is_trivially_copy_assignable()
475
+ //
476
+ // Determines whether the passed type `T` is trivially copy assignable.
477
+ //
478
+ // This metafunction is designed to be a drop-in replacement for the C++11
479
+ // `std::is_trivially_copy_assignable()` metafunction for platforms that have
480
+ // incomplete C++11 support (such as libstdc++ 4.x). On any platforms that do
481
+ // fully support C++11, we check whether this yields the same result as the std
482
+ // implementation.
483
+ //
484
+ // NOTE: `is_assignable<T, U>::value` is `true` if the expression
485
+ // `declval<T>() = declval<U>()` is well-formed when treated as an unevaluated
486
+ // operand. `is_trivially_assignable<T, U>` requires the assignment to call no
487
+ // operation that is not trivial. `is_trivially_copy_assignable<T>` is simply
488
+ // `is_trivially_assignable<T&, const T&>`.
489
+ template <typename T>
490
+ struct is_trivially_copy_assignable
491
+ : std::integral_constant<
492
+ bool, __has_trivial_assign(typename std::remove_reference<T>::type) &&
493
+ absl::is_copy_assignable<T>::value> {
494
+ #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
495
+ private:
496
+ static constexpr bool compliant =
497
+ std::is_trivially_copy_assignable<T>::value ==
498
+ is_trivially_copy_assignable::value;
499
+ static_assert(compliant || std::is_trivially_copy_assignable<T>::value,
500
+ "Not compliant with std::is_trivially_copy_assignable; "
501
+ "Standard: false, Implementation: true");
502
+ static_assert(compliant || !std::is_trivially_copy_assignable<T>::value,
503
+ "Not compliant with std::is_trivially_copy_assignable; "
504
+ "Standard: true, Implementation: false");
505
+ #endif // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
506
+ };
507
+
508
+ namespace type_traits_internal {
509
+ // is_trivially_copyable()
510
+ //
511
+ // Determines whether the passed type `T` is trivially copyable.
512
+ //
513
+ // This metafunction is designed to be a drop-in replacement for the C++11
514
+ // `std::is_trivially_copyable()` metafunction for platforms that have
515
+ // incomplete C++11 support (such as libstdc++ 4.x). We use the C++17 definition
516
+ // of TriviallyCopyable.
517
+ //
518
+ // NOTE: `is_trivially_copyable<T>::value` is `true` if all of T's copy/move
519
+ // constructors/assignment operators are trivial or deleted, T has at least
520
+ // one non-deleted copy/move constructor/assignment operator, and T is trivially
521
+ // destructible. Arrays of trivially copyable types are trivially copyable.
522
+ //
523
+ // We expose this metafunction only for internal use within absl.
524
+ template <typename T>
525
+ class is_trivially_copyable_impl {
526
+ using ExtentsRemoved = typename std::remove_all_extents<T>::type;
527
+ static constexpr bool kIsCopyOrMoveConstructible =
528
+ std::is_copy_constructible<ExtentsRemoved>::value ||
529
+ std::is_move_constructible<ExtentsRemoved>::value;
530
+ static constexpr bool kIsCopyOrMoveAssignable =
531
+ absl::is_copy_assignable<ExtentsRemoved>::value ||
532
+ absl::is_move_assignable<ExtentsRemoved>::value;
533
+
534
+ public:
535
+ static constexpr bool kValue =
536
+ (__has_trivial_copy(ExtentsRemoved) || !kIsCopyOrMoveConstructible) &&
537
+ (__has_trivial_assign(ExtentsRemoved) || !kIsCopyOrMoveAssignable) &&
538
+ (kIsCopyOrMoveConstructible || kIsCopyOrMoveAssignable) &&
539
+ is_trivially_destructible<ExtentsRemoved>::value &&
540
+ // We need to check for this explicitly because otherwise we'll say
541
+ // references are trivial copyable when compiled by MSVC.
542
+ !std::is_reference<ExtentsRemoved>::value;
543
+ };
544
+
545
+ template <typename T>
546
+ struct is_trivially_copyable
547
+ : std::integral_constant<
548
+ bool, type_traits_internal::is_trivially_copyable_impl<T>::kValue> {};
549
+ } // namespace type_traits_internal
550
+
551
+ // -----------------------------------------------------------------------------
552
+ // C++14 "_t" trait aliases
553
+ // -----------------------------------------------------------------------------
554
+
555
+ template <typename T>
556
+ using remove_cv_t = typename std::remove_cv<T>::type;
557
+
558
+ template <typename T>
559
+ using remove_const_t = typename std::remove_const<T>::type;
560
+
561
+ template <typename T>
562
+ using remove_volatile_t = typename std::remove_volatile<T>::type;
563
+
564
+ template <typename T>
565
+ using add_cv_t = typename std::add_cv<T>::type;
566
+
567
+ template <typename T>
568
+ using add_const_t = typename std::add_const<T>::type;
569
+
570
+ template <typename T>
571
+ using add_volatile_t = typename std::add_volatile<T>::type;
572
+
573
+ template <typename T>
574
+ using remove_reference_t = typename std::remove_reference<T>::type;
575
+
576
+ template <typename T>
577
+ using add_lvalue_reference_t = typename std::add_lvalue_reference<T>::type;
578
+
579
+ template <typename T>
580
+ using add_rvalue_reference_t = typename std::add_rvalue_reference<T>::type;
581
+
582
+ template <typename T>
583
+ using remove_pointer_t = typename std::remove_pointer<T>::type;
584
+
585
+ template <typename T>
586
+ using add_pointer_t = typename std::add_pointer<T>::type;
587
+
588
+ template <typename T>
589
+ using make_signed_t = typename std::make_signed<T>::type;
590
+
591
+ template <typename T>
592
+ using make_unsigned_t = typename std::make_unsigned<T>::type;
593
+
594
+ template <typename T>
595
+ using remove_extent_t = typename std::remove_extent<T>::type;
596
+
597
+ template <typename T>
598
+ using remove_all_extents_t = typename std::remove_all_extents<T>::type;
599
+
600
+ template <size_t Len, size_t Align = type_traits_internal::
601
+ default_alignment_of_aligned_storage<Len>::value>
602
+ using aligned_storage_t = typename std::aligned_storage<Len, Align>::type;
603
+
604
+ template <typename T>
605
+ using decay_t = typename std::decay<T>::type;
606
+
607
+ template <bool B, typename T = void>
608
+ using enable_if_t = typename std::enable_if<B, T>::type;
609
+
610
+ template <bool B, typename T, typename F>
611
+ using conditional_t = typename std::conditional<B, T, F>::type;
612
+
613
+ template <typename... T>
614
+ using common_type_t = typename std::common_type<T...>::type;
615
+
616
+ template <typename T>
617
+ using underlying_type_t = typename std::underlying_type<T>::type;
618
+
619
+ template <typename T>
620
+ using result_of_t = typename std::result_of<T>::type;
621
+
622
+ namespace type_traits_internal {
623
+ // In MSVC we can't probe std::hash or stdext::hash because it triggers a
624
+ // static_assert instead of failing substitution. Libc++ prior to 4.0
625
+ // also used a static_assert.
626
+ //
627
+ #if defined(_MSC_VER) || (defined(_LIBCPP_VERSION) && \
628
+ _LIBCPP_VERSION < 4000 && _LIBCPP_STD_VER > 11)
629
+ #define ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_ 0
630
+ #else
631
+ #define ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_ 1
632
+ #endif
633
+
634
+ #if !ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_
635
+ template <typename Key, typename = size_t>
636
+ struct IsHashable : std::true_type {};
637
+ #else // ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_
638
+ template <typename Key, typename = void>
639
+ struct IsHashable : std::false_type {};
640
+
641
+ template <typename Key>
642
+ struct IsHashable<
643
+ Key,
644
+ absl::enable_if_t<std::is_convertible<
645
+ decltype(std::declval<std::hash<Key>&>()(std::declval<Key const&>())),
646
+ std::size_t>::value>> : std::true_type {};
647
+ #endif // !ABSL_META_INTERNAL_STD_HASH_SFINAE_FRIENDLY_
648
+
649
+ struct AssertHashEnabledHelper {
650
+ private:
651
+ static void Sink(...) {}
652
+ struct NAT {};
653
+
654
+ template <class Key>
655
+ static auto GetReturnType(int)
656
+ -> decltype(std::declval<std::hash<Key>>()(std::declval<Key const&>()));
657
+ template <class Key>
658
+ static NAT GetReturnType(...);
659
+
660
+ template <class Key>
661
+ static std::nullptr_t DoIt() {
662
+ static_assert(IsHashable<Key>::value,
663
+ "std::hash<Key> does not provide a call operator");
664
+ static_assert(
665
+ std::is_default_constructible<std::hash<Key>>::value,
666
+ "std::hash<Key> must be default constructible when it is enabled");
667
+ static_assert(
668
+ std::is_copy_constructible<std::hash<Key>>::value,
669
+ "std::hash<Key> must be copy constructible when it is enabled");
670
+ static_assert(absl::is_copy_assignable<std::hash<Key>>::value,
671
+ "std::hash<Key> must be copy assignable when it is enabled");
672
+ // is_destructible is unchecked as it's implied by each of the
673
+ // is_constructible checks.
674
+ using ReturnType = decltype(GetReturnType<Key>(0));
675
+ static_assert(std::is_same<ReturnType, NAT>::value ||
676
+ std::is_same<ReturnType, size_t>::value,
677
+ "std::hash<Key> must return size_t");
678
+ return nullptr;
679
+ }
680
+
681
+ template <class... Ts>
682
+ friend void AssertHashEnabled();
683
+ };
684
+
685
+ template <class... Ts>
686
+ inline void AssertHashEnabled() {
687
+ using Helper = AssertHashEnabledHelper;
688
+ Helper::Sink(Helper::DoIt<Ts>()...);
689
+ }
690
+
691
+ } // namespace type_traits_internal
692
+
693
+ // An internal namespace that is required to implement the C++17 swap traits.
694
+ // It is not further nested in type_traits_internal to avoid long symbol names.
695
+ namespace swap_internal {
696
+
697
+ // Necessary for the traits.
698
+ using std::swap;
699
+
700
+ // This declaration prevents global `swap` and `absl::swap` overloads from being
701
+ // considered unless ADL picks them up.
702
+ void swap();
703
+
704
+ template <class T>
705
+ using IsSwappableImpl = decltype(swap(std::declval<T&>(), std::declval<T&>()));
706
+
707
+ // NOTE: This dance with the default template parameter is for MSVC.
708
+ template <class T,
709
+ class IsNoexcept = std::integral_constant<
710
+ bool, noexcept(swap(std::declval<T&>(), std::declval<T&>()))>>
711
+ using IsNothrowSwappableImpl = typename std::enable_if<IsNoexcept::value>::type;
712
+
713
+ // IsSwappable
714
+ //
715
+ // Determines whether the standard swap idiom is a valid expression for
716
+ // arguments of type `T`.
717
+ template <class T>
718
+ struct IsSwappable
719
+ : absl::type_traits_internal::is_detected<IsSwappableImpl, T> {};
720
+
721
+ // IsNothrowSwappable
722
+ //
723
+ // Determines whether the standard swap idiom is a valid expression for
724
+ // arguments of type `T` and is noexcept.
725
+ template <class T>
726
+ struct IsNothrowSwappable
727
+ : absl::type_traits_internal::is_detected<IsNothrowSwappableImpl, T> {};
728
+
729
+ // Swap()
730
+ //
731
+ // Performs the swap idiom from a namespace where valid candidates may only be
732
+ // found in `std` or via ADL.
733
+ template <class T, absl::enable_if_t<IsSwappable<T>::value, int> = 0>
734
+ void Swap(T& lhs, T& rhs) noexcept(IsNothrowSwappable<T>::value) {
735
+ swap(lhs, rhs);
736
+ }
737
+
738
+ // StdSwapIsUnconstrained
739
+ //
740
+ // Some standard library implementations are broken in that they do not
741
+ // constrain `std::swap`. This will effectively tell us if we are dealing with
742
+ // one of those implementations.
743
+ using StdSwapIsUnconstrained = IsSwappable<void()>;
744
+
745
+ } // namespace swap_internal
746
+
747
+ namespace type_traits_internal {
748
+
749
+ // Make the swap-related traits/function accessible from this namespace.
750
+ using swap_internal::IsNothrowSwappable;
751
+ using swap_internal::IsSwappable;
752
+ using swap_internal::Swap;
753
+ using swap_internal::StdSwapIsUnconstrained;
754
+
755
+ } // namespace type_traits_internal
756
+ ABSL_NAMESPACE_END
757
+ } // namespace absl
758
+
759
+ #endif // ABSL_META_TYPE_TRAITS_H_