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,111 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // -----------------------------------------------------------------------------
16
+ // File: policy_checks.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header enforces a minimum set of policies at build time, such as the
20
+ // supported compiler and library versions. Unsupported configurations are
21
+ // reported with `#error`. This enforcement is best effort, so successfully
22
+ // compiling this header does not guarantee a supported configuration.
23
+
24
+ #ifndef ABSL_BASE_POLICY_CHECKS_H_
25
+ #define ABSL_BASE_POLICY_CHECKS_H_
26
+
27
+ // Included for the __GLIBC_PREREQ macro used below.
28
+ #include <limits.h>
29
+
30
+ // Included for the _STLPORT_VERSION macro used below.
31
+ #if defined(__cplusplus)
32
+ #include <cstddef>
33
+ #endif
34
+
35
+ // -----------------------------------------------------------------------------
36
+ // Operating System Check
37
+ // -----------------------------------------------------------------------------
38
+
39
+ #if defined(__CYGWIN__)
40
+ #error "Cygwin is not supported."
41
+ #endif
42
+
43
+ // -----------------------------------------------------------------------------
44
+ // Compiler Check
45
+ // -----------------------------------------------------------------------------
46
+
47
+ // We support MSVC++ 14.0 update 2 and later.
48
+ // This minimum will go up.
49
+ #if defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918 && !defined(__clang__)
50
+ #error "This package requires Visual Studio 2015 Update 2 or higher."
51
+ #endif
52
+
53
+ // We support gcc 4.7 and later.
54
+ // This minimum will go up.
55
+ #if defined(__GNUC__) && !defined(__clang__)
56
+ #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)
57
+ #error "This package requires gcc 4.7 or higher."
58
+ #endif
59
+ #endif
60
+
61
+ // We support Apple Xcode clang 4.2.1 (version 421.11.65) and later.
62
+ // This corresponds to Apple Xcode version 4.5.
63
+ // This minimum will go up.
64
+ #if defined(__apple_build_version__) && __apple_build_version__ < 4211165
65
+ #error "This package requires __apple_build_version__ of 4211165 or higher."
66
+ #endif
67
+
68
+ // -----------------------------------------------------------------------------
69
+ // C++ Version Check
70
+ // -----------------------------------------------------------------------------
71
+
72
+ // Enforce C++11 as the minimum. Note that Visual Studio has not
73
+ // advanced __cplusplus despite being good enough for our purposes, so
74
+ // so we exempt it from the check.
75
+ #if defined(__cplusplus) && !defined(_MSC_VER)
76
+ #if __cplusplus < 201103L
77
+ #error "C++ versions less than C++11 are not supported."
78
+ #endif
79
+ #endif
80
+
81
+ // -----------------------------------------------------------------------------
82
+ // Standard Library Check
83
+ // -----------------------------------------------------------------------------
84
+
85
+ #if defined(_STLPORT_VERSION)
86
+ #error "STLPort is not supported."
87
+ #endif
88
+
89
+ // -----------------------------------------------------------------------------
90
+ // `char` Size Check
91
+ // -----------------------------------------------------------------------------
92
+
93
+ // Abseil currently assumes CHAR_BIT == 8. If you would like to use Abseil on a
94
+ // platform where this is not the case, please provide us with the details about
95
+ // your platform so we can consider relaxing this requirement.
96
+ #if CHAR_BIT != 8
97
+ #error "Abseil assumes CHAR_BIT == 8."
98
+ #endif
99
+
100
+ // -----------------------------------------------------------------------------
101
+ // `int` Size Check
102
+ // -----------------------------------------------------------------------------
103
+
104
+ // Abseil currently assumes that an int is 4 bytes. If you would like to use
105
+ // Abseil on a platform where this is not the case, please provide us with the
106
+ // details about your platform so we can consider relaxing this requirement.
107
+ #if INT_MAX < 2147483647
108
+ #error "Abseil assumes that int is at least 4 bytes. "
109
+ #endif
110
+
111
+ #endif // ABSL_BASE_POLICY_CHECKS_H_
@@ -0,0 +1,26 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // This files is a forwarding header for other headers containing various
16
+ // portability macros and functions.
17
+ // This file is used for both C and C++!
18
+
19
+ #ifndef ABSL_BASE_PORT_H_
20
+ #define ABSL_BASE_PORT_H_
21
+
22
+ #include "absl/base/attributes.h"
23
+ #include "absl/base/config.h"
24
+ #include "absl/base/optimization.h"
25
+
26
+ #endif // ABSL_BASE_PORT_H_
@@ -0,0 +1,280 @@
1
+ // Copyright 2017 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // -----------------------------------------------------------------------------
16
+ // File: thread_annotations.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file contains macro definitions for thread safety annotations
20
+ // that allow developers to document the locking policies of multi-threaded
21
+ // code. The annotations can also help program analysis tools to identify
22
+ // potential thread safety issues.
23
+ //
24
+ // These annotations are implemented using compiler attributes. Using the macros
25
+ // defined here instead of raw attributes allow for portability and future
26
+ // compatibility.
27
+ //
28
+ // When referring to mutexes in the arguments of the attributes, you should
29
+ // use variable names or more complex expressions (e.g. my_object->mutex_)
30
+ // that evaluate to a concrete mutex object whenever possible. If the mutex
31
+ // you want to refer to is not in scope, you may use a member pointer
32
+ // (e.g. &MyClass::mutex_) to refer to a mutex in some (unknown) object.
33
+
34
+ #ifndef ABSL_BASE_THREAD_ANNOTATIONS_H_
35
+ #define ABSL_BASE_THREAD_ANNOTATIONS_H_
36
+
37
+ #include "absl/base/config.h"
38
+ // TODO(mbonadei): Remove after the backward compatibility period.
39
+ #include "absl/base/internal/thread_annotations.h" // IWYU pragma: export
40
+
41
+ #if defined(__clang__)
42
+ #define ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(x) __attribute__((x))
43
+ #else
44
+ #define ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(x) // no-op
45
+ #endif
46
+
47
+ // ABSL_GUARDED_BY()
48
+ //
49
+ // Documents if a shared field or global variable needs to be protected by a
50
+ // mutex. ABSL_GUARDED_BY() allows the user to specify a particular mutex that
51
+ // should be held when accessing the annotated variable.
52
+ //
53
+ // Although this annotation (and ABSL_PT_GUARDED_BY, below) cannot be applied to
54
+ // local variables, a local variable and its associated mutex can often be
55
+ // combined into a small class or struct, thereby allowing the annotation.
56
+ //
57
+ // Example:
58
+ //
59
+ // class Foo {
60
+ // Mutex mu_;
61
+ // int p1_ ABSL_GUARDED_BY(mu_);
62
+ // ...
63
+ // };
64
+ #define ABSL_GUARDED_BY(x) \
65
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(guarded_by(x))
66
+
67
+ // ABSL_PT_GUARDED_BY()
68
+ //
69
+ // Documents if the memory location pointed to by a pointer should be guarded
70
+ // by a mutex when dereferencing the pointer.
71
+ //
72
+ // Example:
73
+ // class Foo {
74
+ // Mutex mu_;
75
+ // int *p1_ ABSL_PT_GUARDED_BY(mu_);
76
+ // ...
77
+ // };
78
+ //
79
+ // Note that a pointer variable to a shared memory location could itself be a
80
+ // shared variable.
81
+ //
82
+ // Example:
83
+ //
84
+ // // `q_`, guarded by `mu1_`, points to a shared memory location that is
85
+ // // guarded by `mu2_`:
86
+ // int *q_ ABSL_GUARDED_BY(mu1_) ABSL_PT_GUARDED_BY(mu2_);
87
+ #define ABSL_PT_GUARDED_BY(x) \
88
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(pt_guarded_by(x))
89
+
90
+ // ABSL_ACQUIRED_AFTER() / ABSL_ACQUIRED_BEFORE()
91
+ //
92
+ // Documents the acquisition order between locks that can be held
93
+ // simultaneously by a thread. For any two locks that need to be annotated
94
+ // to establish an acquisition order, only one of them needs the annotation.
95
+ // (i.e. You don't have to annotate both locks with both ABSL_ACQUIRED_AFTER
96
+ // and ABSL_ACQUIRED_BEFORE.)
97
+ //
98
+ // As with ABSL_GUARDED_BY, this is only applicable to mutexes that are shared
99
+ // fields or global variables.
100
+ //
101
+ // Example:
102
+ //
103
+ // Mutex m1_;
104
+ // Mutex m2_ ABSL_ACQUIRED_AFTER(m1_);
105
+ #define ABSL_ACQUIRED_AFTER(...) \
106
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(acquired_after(__VA_ARGS__))
107
+
108
+ #define ABSL_ACQUIRED_BEFORE(...) \
109
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(acquired_before(__VA_ARGS__))
110
+
111
+ // ABSL_EXCLUSIVE_LOCKS_REQUIRED() / ABSL_SHARED_LOCKS_REQUIRED()
112
+ //
113
+ // Documents a function that expects a mutex to be held prior to entry.
114
+ // The mutex is expected to be held both on entry to, and exit from, the
115
+ // function.
116
+ //
117
+ // An exclusive lock allows read-write access to the guarded data member(s), and
118
+ // only one thread can acquire a lock exclusively at any one time. A shared lock
119
+ // allows read-only access, and any number of threads can acquire a shared lock
120
+ // concurrently.
121
+ //
122
+ // Generally, non-const methods should be annotated with
123
+ // ABSL_EXCLUSIVE_LOCKS_REQUIRED, while const methods should be annotated with
124
+ // ABSL_SHARED_LOCKS_REQUIRED.
125
+ //
126
+ // Example:
127
+ //
128
+ // Mutex mu1, mu2;
129
+ // int a ABSL_GUARDED_BY(mu1);
130
+ // int b ABSL_GUARDED_BY(mu2);
131
+ //
132
+ // void foo() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu1, mu2) { ... }
133
+ // void bar() const ABSL_SHARED_LOCKS_REQUIRED(mu1, mu2) { ... }
134
+ #define ABSL_EXCLUSIVE_LOCKS_REQUIRED(...) \
135
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE( \
136
+ exclusive_locks_required(__VA_ARGS__))
137
+
138
+ #define ABSL_SHARED_LOCKS_REQUIRED(...) \
139
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(shared_locks_required(__VA_ARGS__))
140
+
141
+ // ABSL_LOCKS_EXCLUDED()
142
+ //
143
+ // Documents the locks acquired in the body of the function. These locks
144
+ // cannot be held when calling this function (as Abseil's `Mutex` locks are
145
+ // non-reentrant).
146
+ #define ABSL_LOCKS_EXCLUDED(...) \
147
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(locks_excluded(__VA_ARGS__))
148
+
149
+ // ABSL_LOCK_RETURNED()
150
+ //
151
+ // Documents a function that returns a mutex without acquiring it. For example,
152
+ // a public getter method that returns a pointer to a private mutex should
153
+ // be annotated with ABSL_LOCK_RETURNED.
154
+ #define ABSL_LOCK_RETURNED(x) \
155
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(lock_returned(x))
156
+
157
+ // ABSL_LOCKABLE
158
+ //
159
+ // Documents if a class/type is a lockable type (such as the `Mutex` class).
160
+ #define ABSL_LOCKABLE ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(lockable)
161
+
162
+ // ABSL_SCOPED_LOCKABLE
163
+ //
164
+ // Documents if a class does RAII locking (such as the `MutexLock` class).
165
+ // The constructor should use `LOCK_FUNCTION()` to specify the mutex that is
166
+ // acquired, and the destructor should use `UNLOCK_FUNCTION()` with no
167
+ // arguments; the analysis will assume that the destructor unlocks whatever the
168
+ // constructor locked.
169
+ #define ABSL_SCOPED_LOCKABLE \
170
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(scoped_lockable)
171
+
172
+ // ABSL_EXCLUSIVE_LOCK_FUNCTION()
173
+ //
174
+ // Documents functions that acquire a lock in the body of a function, and do
175
+ // not release it.
176
+ #define ABSL_EXCLUSIVE_LOCK_FUNCTION(...) \
177
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE( \
178
+ exclusive_lock_function(__VA_ARGS__))
179
+
180
+ // ABSL_SHARED_LOCK_FUNCTION()
181
+ //
182
+ // Documents functions that acquire a shared (reader) lock in the body of a
183
+ // function, and do not release it.
184
+ #define ABSL_SHARED_LOCK_FUNCTION(...) \
185
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(shared_lock_function(__VA_ARGS__))
186
+
187
+ // ABSL_UNLOCK_FUNCTION()
188
+ //
189
+ // Documents functions that expect a lock to be held on entry to the function,
190
+ // and release it in the body of the function.
191
+ #define ABSL_UNLOCK_FUNCTION(...) \
192
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(unlock_function(__VA_ARGS__))
193
+
194
+ // ABSL_EXCLUSIVE_TRYLOCK_FUNCTION() / ABSL_SHARED_TRYLOCK_FUNCTION()
195
+ //
196
+ // Documents functions that try to acquire a lock, and return success or failure
197
+ // (or a non-boolean value that can be interpreted as a boolean).
198
+ // The first argument should be `true` for functions that return `true` on
199
+ // success, or `false` for functions that return `false` on success. The second
200
+ // argument specifies the mutex that is locked on success. If unspecified, this
201
+ // mutex is assumed to be `this`.
202
+ #define ABSL_EXCLUSIVE_TRYLOCK_FUNCTION(...) \
203
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE( \
204
+ exclusive_trylock_function(__VA_ARGS__))
205
+
206
+ #define ABSL_SHARED_TRYLOCK_FUNCTION(...) \
207
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE( \
208
+ shared_trylock_function(__VA_ARGS__))
209
+
210
+ // ABSL_ASSERT_EXCLUSIVE_LOCK() / ABSL_ASSERT_SHARED_LOCK()
211
+ //
212
+ // Documents functions that dynamically check to see if a lock is held, and fail
213
+ // if it is not held.
214
+ #define ABSL_ASSERT_EXCLUSIVE_LOCK(...) \
215
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(assert_exclusive_lock(__VA_ARGS__))
216
+
217
+ #define ABSL_ASSERT_SHARED_LOCK(...) \
218
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(assert_shared_lock(__VA_ARGS__))
219
+
220
+ // ABSL_NO_THREAD_SAFETY_ANALYSIS
221
+ //
222
+ // Turns off thread safety checking within the body of a particular function.
223
+ // This annotation is used to mark functions that are known to be correct, but
224
+ // the locking behavior is more complicated than the analyzer can handle.
225
+ #define ABSL_NO_THREAD_SAFETY_ANALYSIS \
226
+ ABSL_INTERNAL_THREAD_ANNOTATION_ATTRIBUTE(no_thread_safety_analysis)
227
+
228
+ //------------------------------------------------------------------------------
229
+ // Tool-Supplied Annotations
230
+ //------------------------------------------------------------------------------
231
+
232
+ // ABSL_TS_UNCHECKED should be placed around lock expressions that are not valid
233
+ // C++ syntax, but which are present for documentation purposes. These
234
+ // annotations will be ignored by the analysis.
235
+ #define ABSL_TS_UNCHECKED(x) ""
236
+
237
+ // ABSL_TS_FIXME is used to mark lock expressions that are not valid C++ syntax.
238
+ // It is used by automated tools to mark and disable invalid expressions.
239
+ // The annotation should either be fixed, or changed to ABSL_TS_UNCHECKED.
240
+ #define ABSL_TS_FIXME(x) ""
241
+
242
+ // Like ABSL_NO_THREAD_SAFETY_ANALYSIS, this turns off checking within the body
243
+ // of a particular function. However, this attribute is used to mark functions
244
+ // that are incorrect and need to be fixed. It is used by automated tools to
245
+ // avoid breaking the build when the analysis is updated.
246
+ // Code owners are expected to eventually fix the routine.
247
+ #define ABSL_NO_THREAD_SAFETY_ANALYSIS_FIXME ABSL_NO_THREAD_SAFETY_ANALYSIS
248
+
249
+ // Similar to ABSL_NO_THREAD_SAFETY_ANALYSIS_FIXME, this macro marks a
250
+ // ABSL_GUARDED_BY annotation that needs to be fixed, because it is producing
251
+ // thread safety warning. It disables the ABSL_GUARDED_BY.
252
+ #define ABSL_GUARDED_BY_FIXME(x)
253
+
254
+ // Disables warnings for a single read operation. This can be used to avoid
255
+ // warnings when it is known that the read is not actually involved in a race,
256
+ // but the compiler cannot confirm that.
257
+ #define ABSL_TS_UNCHECKED_READ(x) absl::base_internal::ts_unchecked_read(x)
258
+
259
+ namespace absl {
260
+ ABSL_NAMESPACE_BEGIN
261
+ namespace base_internal {
262
+
263
+ // Takes a reference to a guarded data member, and returns an unguarded
264
+ // reference.
265
+ // Do not used this function directly, use ABSL_TS_UNCHECKED_READ instead.
266
+ template <typename T>
267
+ inline const T& ts_unchecked_read(const T& v) ABSL_NO_THREAD_SAFETY_ANALYSIS {
268
+ return v;
269
+ }
270
+
271
+ template <typename T>
272
+ inline T& ts_unchecked_read(T& v) ABSL_NO_THREAD_SAFETY_ANALYSIS {
273
+ return v;
274
+ }
275
+
276
+ } // namespace base_internal
277
+ ABSL_NAMESPACE_END
278
+ } // namespace absl
279
+
280
+ #endif // ABSL_BASE_THREAD_ANNOTATIONS_H_
@@ -0,0 +1,848 @@
1
+ // Copyright 2019 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // -----------------------------------------------------------------------------
16
+ // File: inlined_vector.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file contains the declaration and definition of an "inlined
20
+ // vector" which behaves in an equivalent fashion to a `std::vector`, except
21
+ // that storage for small sequences of the vector are provided inline without
22
+ // requiring any heap allocation.
23
+ //
24
+ // An `absl::InlinedVector<T, N>` specifies the default capacity `N` as one of
25
+ // its template parameters. Instances where `size() <= N` hold contained
26
+ // elements in inline space. Typically `N` is very small so that sequences that
27
+ // are expected to be short do not require allocations.
28
+ //
29
+ // An `absl::InlinedVector` does not usually require a specific allocator. If
30
+ // the inlined vector grows beyond its initial constraints, it will need to
31
+ // allocate (as any normal `std::vector` would). This is usually performed with
32
+ // the default allocator (defined as `std::allocator<T>`). Optionally, a custom
33
+ // allocator type may be specified as `A` in `absl::InlinedVector<T, N, A>`.
34
+
35
+ #ifndef ABSL_CONTAINER_INLINED_VECTOR_H_
36
+ #define ABSL_CONTAINER_INLINED_VECTOR_H_
37
+
38
+ #include <algorithm>
39
+ #include <cassert>
40
+ #include <cstddef>
41
+ #include <cstdlib>
42
+ #include <cstring>
43
+ #include <initializer_list>
44
+ #include <iterator>
45
+ #include <memory>
46
+ #include <type_traits>
47
+ #include <utility>
48
+
49
+ #include "absl/algorithm/algorithm.h"
50
+ #include "absl/base/internal/throw_delegate.h"
51
+ #include "absl/base/optimization.h"
52
+ #include "absl/base/port.h"
53
+ #include "absl/container/internal/inlined_vector.h"
54
+ #include "absl/memory/memory.h"
55
+
56
+ namespace absl {
57
+ ABSL_NAMESPACE_BEGIN
58
+ // -----------------------------------------------------------------------------
59
+ // InlinedVector
60
+ // -----------------------------------------------------------------------------
61
+ //
62
+ // An `absl::InlinedVector` is designed to be a drop-in replacement for
63
+ // `std::vector` for use cases where the vector's size is sufficiently small
64
+ // that it can be inlined. If the inlined vector does grow beyond its estimated
65
+ // capacity, it will trigger an initial allocation on the heap, and will behave
66
+ // as a `std:vector`. The API of the `absl::InlinedVector` within this file is
67
+ // designed to cover the same API footprint as covered by `std::vector`.
68
+ template <typename T, size_t N, typename A = std::allocator<T>>
69
+ class InlinedVector {
70
+ static_assert(N > 0, "`absl::InlinedVector` requires an inlined capacity.");
71
+
72
+ using Storage = inlined_vector_internal::Storage<T, N, A>;
73
+
74
+ using AllocatorTraits = typename Storage::AllocatorTraits;
75
+ using RValueReference = typename Storage::RValueReference;
76
+ using MoveIterator = typename Storage::MoveIterator;
77
+ using IsMemcpyOk = typename Storage::IsMemcpyOk;
78
+
79
+ template <typename Iterator>
80
+ using IteratorValueAdapter =
81
+ typename Storage::template IteratorValueAdapter<Iterator>;
82
+ using CopyValueAdapter = typename Storage::CopyValueAdapter;
83
+ using DefaultValueAdapter = typename Storage::DefaultValueAdapter;
84
+
85
+ template <typename Iterator>
86
+ using EnableIfAtLeastForwardIterator = absl::enable_if_t<
87
+ inlined_vector_internal::IsAtLeastForwardIterator<Iterator>::value>;
88
+ template <typename Iterator>
89
+ using DisableIfAtLeastForwardIterator = absl::enable_if_t<
90
+ !inlined_vector_internal::IsAtLeastForwardIterator<Iterator>::value>;
91
+
92
+ public:
93
+ using allocator_type = typename Storage::allocator_type;
94
+ using value_type = typename Storage::value_type;
95
+ using pointer = typename Storage::pointer;
96
+ using const_pointer = typename Storage::const_pointer;
97
+ using size_type = typename Storage::size_type;
98
+ using difference_type = typename Storage::difference_type;
99
+ using reference = typename Storage::reference;
100
+ using const_reference = typename Storage::const_reference;
101
+ using iterator = typename Storage::iterator;
102
+ using const_iterator = typename Storage::const_iterator;
103
+ using reverse_iterator = typename Storage::reverse_iterator;
104
+ using const_reverse_iterator = typename Storage::const_reverse_iterator;
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // InlinedVector Constructors and Destructor
108
+ // ---------------------------------------------------------------------------
109
+
110
+ // Creates an empty inlined vector with a value-initialized allocator.
111
+ InlinedVector() noexcept(noexcept(allocator_type())) : storage_() {}
112
+
113
+ // Creates an empty inlined vector with a copy of `alloc`.
114
+ explicit InlinedVector(const allocator_type& alloc) noexcept
115
+ : storage_(alloc) {}
116
+
117
+ // Creates an inlined vector with `n` copies of `value_type()`.
118
+ explicit InlinedVector(size_type n,
119
+ const allocator_type& alloc = allocator_type())
120
+ : storage_(alloc) {
121
+ storage_.Initialize(DefaultValueAdapter(), n);
122
+ }
123
+
124
+ // Creates an inlined vector with `n` copies of `v`.
125
+ InlinedVector(size_type n, const_reference v,
126
+ const allocator_type& alloc = allocator_type())
127
+ : storage_(alloc) {
128
+ storage_.Initialize(CopyValueAdapter(v), n);
129
+ }
130
+
131
+ // Creates an inlined vector with copies of the elements of `list`.
132
+ InlinedVector(std::initializer_list<value_type> list,
133
+ const allocator_type& alloc = allocator_type())
134
+ : InlinedVector(list.begin(), list.end(), alloc) {}
135
+
136
+ // Creates an inlined vector with elements constructed from the provided
137
+ // forward iterator range [`first`, `last`).
138
+ //
139
+ // NOTE: the `enable_if` prevents ambiguous interpretation between a call to
140
+ // this constructor with two integral arguments and a call to the above
141
+ // `InlinedVector(size_type, const_reference)` constructor.
142
+ template <typename ForwardIterator,
143
+ EnableIfAtLeastForwardIterator<ForwardIterator>* = nullptr>
144
+ InlinedVector(ForwardIterator first, ForwardIterator last,
145
+ const allocator_type& alloc = allocator_type())
146
+ : storage_(alloc) {
147
+ storage_.Initialize(IteratorValueAdapter<ForwardIterator>(first),
148
+ std::distance(first, last));
149
+ }
150
+
151
+ // Creates an inlined vector with elements constructed from the provided input
152
+ // iterator range [`first`, `last`).
153
+ template <typename InputIterator,
154
+ DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
155
+ InlinedVector(InputIterator first, InputIterator last,
156
+ const allocator_type& alloc = allocator_type())
157
+ : storage_(alloc) {
158
+ std::copy(first, last, std::back_inserter(*this));
159
+ }
160
+
161
+ // Creates an inlined vector by copying the contents of `other` using
162
+ // `other`'s allocator.
163
+ InlinedVector(const InlinedVector& other)
164
+ : InlinedVector(other, *other.storage_.GetAllocPtr()) {}
165
+
166
+ // Creates an inlined vector by copying the contents of `other` using `alloc`.
167
+ InlinedVector(const InlinedVector& other, const allocator_type& alloc)
168
+ : storage_(alloc) {
169
+ if (IsMemcpyOk::value && !other.storage_.GetIsAllocated()) {
170
+ storage_.MemcpyFrom(other.storage_);
171
+ } else {
172
+ storage_.Initialize(IteratorValueAdapter<const_pointer>(other.data()),
173
+ other.size());
174
+ }
175
+ }
176
+
177
+ // Creates an inlined vector by moving in the contents of `other` without
178
+ // allocating. If `other` contains allocated memory, the newly-created inlined
179
+ // vector will take ownership of that memory. However, if `other` does not
180
+ // contain allocated memory, the newly-created inlined vector will perform
181
+ // element-wise move construction of the contents of `other`.
182
+ //
183
+ // NOTE: since no allocation is performed for the inlined vector in either
184
+ // case, the `noexcept(...)` specification depends on whether moving the
185
+ // underlying objects can throw. It is assumed assumed that...
186
+ // a) move constructors should only throw due to allocation failure.
187
+ // b) if `value_type`'s move constructor allocates, it uses the same
188
+ // allocation function as the inlined vector's allocator.
189
+ // Thus, the move constructor is non-throwing if the allocator is non-throwing
190
+ // or `value_type`'s move constructor is specified as `noexcept`.
191
+ InlinedVector(InlinedVector&& other) noexcept(
192
+ absl::allocator_is_nothrow<allocator_type>::value ||
193
+ std::is_nothrow_move_constructible<value_type>::value)
194
+ : storage_(*other.storage_.GetAllocPtr()) {
195
+ if (IsMemcpyOk::value) {
196
+ storage_.MemcpyFrom(other.storage_);
197
+
198
+ other.storage_.SetInlinedSize(0);
199
+ } else if (other.storage_.GetIsAllocated()) {
200
+ storage_.SetAllocatedData(other.storage_.GetAllocatedData(),
201
+ other.storage_.GetAllocatedCapacity());
202
+ storage_.SetAllocatedSize(other.storage_.GetSize());
203
+
204
+ other.storage_.SetInlinedSize(0);
205
+ } else {
206
+ IteratorValueAdapter<MoveIterator> other_values(
207
+ MoveIterator(other.storage_.GetInlinedData()));
208
+
209
+ inlined_vector_internal::ConstructElements(
210
+ storage_.GetAllocPtr(), storage_.GetInlinedData(), &other_values,
211
+ other.storage_.GetSize());
212
+
213
+ storage_.SetInlinedSize(other.storage_.GetSize());
214
+ }
215
+ }
216
+
217
+ // Creates an inlined vector by moving in the contents of `other` with a copy
218
+ // of `alloc`.
219
+ //
220
+ // NOTE: if `other`'s allocator is not equal to `alloc`, even if `other`
221
+ // contains allocated memory, this move constructor will still allocate. Since
222
+ // allocation is performed, this constructor can only be `noexcept` if the
223
+ // specified allocator is also `noexcept`.
224
+ InlinedVector(InlinedVector&& other, const allocator_type& alloc) noexcept(
225
+ absl::allocator_is_nothrow<allocator_type>::value)
226
+ : storage_(alloc) {
227
+ if (IsMemcpyOk::value) {
228
+ storage_.MemcpyFrom(other.storage_);
229
+
230
+ other.storage_.SetInlinedSize(0);
231
+ } else if ((*storage_.GetAllocPtr() == *other.storage_.GetAllocPtr()) &&
232
+ other.storage_.GetIsAllocated()) {
233
+ storage_.SetAllocatedData(other.storage_.GetAllocatedData(),
234
+ other.storage_.GetAllocatedCapacity());
235
+ storage_.SetAllocatedSize(other.storage_.GetSize());
236
+
237
+ other.storage_.SetInlinedSize(0);
238
+ } else {
239
+ storage_.Initialize(
240
+ IteratorValueAdapter<MoveIterator>(MoveIterator(other.data())),
241
+ other.size());
242
+ }
243
+ }
244
+
245
+ ~InlinedVector() {}
246
+
247
+ // ---------------------------------------------------------------------------
248
+ // InlinedVector Member Accessors
249
+ // ---------------------------------------------------------------------------
250
+
251
+ // `InlinedVector::empty()`
252
+ //
253
+ // Returns whether the inlined vector contains no elements.
254
+ bool empty() const noexcept { return !size(); }
255
+
256
+ // `InlinedVector::size()`
257
+ //
258
+ // Returns the number of elements in the inlined vector.
259
+ size_type size() const noexcept { return storage_.GetSize(); }
260
+
261
+ // `InlinedVector::max_size()`
262
+ //
263
+ // Returns the maximum number of elements the inlined vector can hold.
264
+ size_type max_size() const noexcept {
265
+ // One bit of the size storage is used to indicate whether the inlined
266
+ // vector contains allocated memory. As a result, the maximum size that the
267
+ // inlined vector can express is half of the max for `size_type`.
268
+ return (std::numeric_limits<size_type>::max)() / 2;
269
+ }
270
+
271
+ // `InlinedVector::capacity()`
272
+ //
273
+ // Returns the number of elements that could be stored in the inlined vector
274
+ // without requiring a reallocation.
275
+ //
276
+ // NOTE: for most inlined vectors, `capacity()` should be equal to the
277
+ // template parameter `N`. For inlined vectors which exceed this capacity,
278
+ // they will no longer be inlined and `capacity()` will equal the capactity of
279
+ // the allocated memory.
280
+ size_type capacity() const noexcept {
281
+ return storage_.GetIsAllocated() ? storage_.GetAllocatedCapacity()
282
+ : storage_.GetInlinedCapacity();
283
+ }
284
+
285
+ // `InlinedVector::data()`
286
+ //
287
+ // Returns a `pointer` to the elements of the inlined vector. This pointer
288
+ // can be used to access and modify the contained elements.
289
+ //
290
+ // NOTE: only elements within [`data()`, `data() + size()`) are valid.
291
+ pointer data() noexcept {
292
+ return storage_.GetIsAllocated() ? storage_.GetAllocatedData()
293
+ : storage_.GetInlinedData();
294
+ }
295
+
296
+ // Overload of `InlinedVector::data()` that returns a `const_pointer` to the
297
+ // elements of the inlined vector. This pointer can be used to access but not
298
+ // modify the contained elements.
299
+ //
300
+ // NOTE: only elements within [`data()`, `data() + size()`) are valid.
301
+ const_pointer data() const noexcept {
302
+ return storage_.GetIsAllocated() ? storage_.GetAllocatedData()
303
+ : storage_.GetInlinedData();
304
+ }
305
+
306
+ // `InlinedVector::operator[](...)`
307
+ //
308
+ // Returns a `reference` to the `i`th element of the inlined vector.
309
+ reference operator[](size_type i) {
310
+ assert(i < size());
311
+
312
+ return data()[i];
313
+ }
314
+
315
+ // Overload of `InlinedVector::operator[](...)` that returns a
316
+ // `const_reference` to the `i`th element of the inlined vector.
317
+ const_reference operator[](size_type i) const {
318
+ assert(i < size());
319
+
320
+ return data()[i];
321
+ }
322
+
323
+ // `InlinedVector::at(...)`
324
+ //
325
+ // Returns a `reference` to the `i`th element of the inlined vector.
326
+ //
327
+ // NOTE: if `i` is not within the required range of `InlinedVector::at(...)`,
328
+ // in both debug and non-debug builds, `std::out_of_range` will be thrown.
329
+ reference at(size_type i) {
330
+ if (ABSL_PREDICT_FALSE(i >= size())) {
331
+ base_internal::ThrowStdOutOfRange(
332
+ "`InlinedVector::at(size_type)` failed bounds check");
333
+ }
334
+
335
+ return data()[i];
336
+ }
337
+
338
+ // Overload of `InlinedVector::at(...)` that returns a `const_reference` to
339
+ // the `i`th element of the inlined vector.
340
+ //
341
+ // NOTE: if `i` is not within the required range of `InlinedVector::at(...)`,
342
+ // in both debug and non-debug builds, `std::out_of_range` will be thrown.
343
+ const_reference at(size_type i) const {
344
+ if (ABSL_PREDICT_FALSE(i >= size())) {
345
+ base_internal::ThrowStdOutOfRange(
346
+ "`InlinedVector::at(size_type) const` failed bounds check");
347
+ }
348
+
349
+ return data()[i];
350
+ }
351
+
352
+ // `InlinedVector::front()`
353
+ //
354
+ // Returns a `reference` to the first element of the inlined vector.
355
+ reference front() {
356
+ assert(!empty());
357
+
358
+ return at(0);
359
+ }
360
+
361
+ // Overload of `InlinedVector::front()` that returns a `const_reference` to
362
+ // the first element of the inlined vector.
363
+ const_reference front() const {
364
+ assert(!empty());
365
+
366
+ return at(0);
367
+ }
368
+
369
+ // `InlinedVector::back()`
370
+ //
371
+ // Returns a `reference` to the last element of the inlined vector.
372
+ reference back() {
373
+ assert(!empty());
374
+
375
+ return at(size() - 1);
376
+ }
377
+
378
+ // Overload of `InlinedVector::back()` that returns a `const_reference` to the
379
+ // last element of the inlined vector.
380
+ const_reference back() const {
381
+ assert(!empty());
382
+
383
+ return at(size() - 1);
384
+ }
385
+
386
+ // `InlinedVector::begin()`
387
+ //
388
+ // Returns an `iterator` to the beginning of the inlined vector.
389
+ iterator begin() noexcept { return data(); }
390
+
391
+ // Overload of `InlinedVector::begin()` that returns a `const_iterator` to
392
+ // the beginning of the inlined vector.
393
+ const_iterator begin() const noexcept { return data(); }
394
+
395
+ // `InlinedVector::end()`
396
+ //
397
+ // Returns an `iterator` to the end of the inlined vector.
398
+ iterator end() noexcept { return data() + size(); }
399
+
400
+ // Overload of `InlinedVector::end()` that returns a `const_iterator` to the
401
+ // end of the inlined vector.
402
+ const_iterator end() const noexcept { return data() + size(); }
403
+
404
+ // `InlinedVector::cbegin()`
405
+ //
406
+ // Returns a `const_iterator` to the beginning of the inlined vector.
407
+ const_iterator cbegin() const noexcept { return begin(); }
408
+
409
+ // `InlinedVector::cend()`
410
+ //
411
+ // Returns a `const_iterator` to the end of the inlined vector.
412
+ const_iterator cend() const noexcept { return end(); }
413
+
414
+ // `InlinedVector::rbegin()`
415
+ //
416
+ // Returns a `reverse_iterator` from the end of the inlined vector.
417
+ reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
418
+
419
+ // Overload of `InlinedVector::rbegin()` that returns a
420
+ // `const_reverse_iterator` from the end of the inlined vector.
421
+ const_reverse_iterator rbegin() const noexcept {
422
+ return const_reverse_iterator(end());
423
+ }
424
+
425
+ // `InlinedVector::rend()`
426
+ //
427
+ // Returns a `reverse_iterator` from the beginning of the inlined vector.
428
+ reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
429
+
430
+ // Overload of `InlinedVector::rend()` that returns a `const_reverse_iterator`
431
+ // from the beginning of the inlined vector.
432
+ const_reverse_iterator rend() const noexcept {
433
+ return const_reverse_iterator(begin());
434
+ }
435
+
436
+ // `InlinedVector::crbegin()`
437
+ //
438
+ // Returns a `const_reverse_iterator` from the end of the inlined vector.
439
+ const_reverse_iterator crbegin() const noexcept { return rbegin(); }
440
+
441
+ // `InlinedVector::crend()`
442
+ //
443
+ // Returns a `const_reverse_iterator` from the beginning of the inlined
444
+ // vector.
445
+ const_reverse_iterator crend() const noexcept { return rend(); }
446
+
447
+ // `InlinedVector::get_allocator()`
448
+ //
449
+ // Returns a copy of the inlined vector's allocator.
450
+ allocator_type get_allocator() const { return *storage_.GetAllocPtr(); }
451
+
452
+ // ---------------------------------------------------------------------------
453
+ // InlinedVector Member Mutators
454
+ // ---------------------------------------------------------------------------
455
+
456
+ // `InlinedVector::operator=(...)`
457
+ //
458
+ // Replaces the elements of the inlined vector with copies of the elements of
459
+ // `list`.
460
+ InlinedVector& operator=(std::initializer_list<value_type> list) {
461
+ assign(list.begin(), list.end());
462
+
463
+ return *this;
464
+ }
465
+
466
+ // Overload of `InlinedVector::operator=(...)` that replaces the elements of
467
+ // the inlined vector with copies of the elements of `other`.
468
+ InlinedVector& operator=(const InlinedVector& other) {
469
+ if (ABSL_PREDICT_TRUE(this != std::addressof(other))) {
470
+ const_pointer other_data = other.data();
471
+ assign(other_data, other_data + other.size());
472
+ }
473
+
474
+ return *this;
475
+ }
476
+
477
+ // Overload of `InlinedVector::operator=(...)` that moves the elements of
478
+ // `other` into the inlined vector.
479
+ //
480
+ // NOTE: as a result of calling this overload, `other` is left in a valid but
481
+ // unspecified state.
482
+ InlinedVector& operator=(InlinedVector&& other) {
483
+ if (ABSL_PREDICT_TRUE(this != std::addressof(other))) {
484
+ if (IsMemcpyOk::value || other.storage_.GetIsAllocated()) {
485
+ inlined_vector_internal::DestroyElements(storage_.GetAllocPtr(), data(),
486
+ size());
487
+ storage_.DeallocateIfAllocated();
488
+ storage_.MemcpyFrom(other.storage_);
489
+
490
+ other.storage_.SetInlinedSize(0);
491
+ } else {
492
+ storage_.Assign(IteratorValueAdapter<MoveIterator>(
493
+ MoveIterator(other.storage_.GetInlinedData())),
494
+ other.size());
495
+ }
496
+ }
497
+
498
+ return *this;
499
+ }
500
+
501
+ // `InlinedVector::assign(...)`
502
+ //
503
+ // Replaces the contents of the inlined vector with `n` copies of `v`.
504
+ void assign(size_type n, const_reference v) {
505
+ storage_.Assign(CopyValueAdapter(v), n);
506
+ }
507
+
508
+ // Overload of `InlinedVector::assign(...)` that replaces the contents of the
509
+ // inlined vector with copies of the elements of `list`.
510
+ void assign(std::initializer_list<value_type> list) {
511
+ assign(list.begin(), list.end());
512
+ }
513
+
514
+ // Overload of `InlinedVector::assign(...)` to replace the contents of the
515
+ // inlined vector with the range [`first`, `last`).
516
+ //
517
+ // NOTE: this overload is for iterators that are "forward" category or better.
518
+ template <typename ForwardIterator,
519
+ EnableIfAtLeastForwardIterator<ForwardIterator>* = nullptr>
520
+ void assign(ForwardIterator first, ForwardIterator last) {
521
+ storage_.Assign(IteratorValueAdapter<ForwardIterator>(first),
522
+ std::distance(first, last));
523
+ }
524
+
525
+ // Overload of `InlinedVector::assign(...)` to replace the contents of the
526
+ // inlined vector with the range [`first`, `last`).
527
+ //
528
+ // NOTE: this overload is for iterators that are "input" category.
529
+ template <typename InputIterator,
530
+ DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
531
+ void assign(InputIterator first, InputIterator last) {
532
+ size_type i = 0;
533
+ for (; i < size() && first != last; ++i, static_cast<void>(++first)) {
534
+ at(i) = *first;
535
+ }
536
+
537
+ erase(data() + i, data() + size());
538
+ std::copy(first, last, std::back_inserter(*this));
539
+ }
540
+
541
+ // `InlinedVector::resize(...)`
542
+ //
543
+ // Resizes the inlined vector to contain `n` elements.
544
+ //
545
+ // NOTE: if `n` is smaller than `size()`, extra elements are destroyed. If `n`
546
+ // is larger than `size()`, new elements are value-initialized.
547
+ void resize(size_type n) { storage_.Resize(DefaultValueAdapter(), n); }
548
+
549
+ // Overload of `InlinedVector::resize(...)` that resizes the inlined vector to
550
+ // contain `n` elements.
551
+ //
552
+ // NOTE: if `n` is smaller than `size()`, extra elements are destroyed. If `n`
553
+ // is larger than `size()`, new elements are copied-constructed from `v`.
554
+ void resize(size_type n, const_reference v) {
555
+ storage_.Resize(CopyValueAdapter(v), n);
556
+ }
557
+
558
+ // `InlinedVector::insert(...)`
559
+ //
560
+ // Inserts a copy of `v` at `pos`, returning an `iterator` to the newly
561
+ // inserted element.
562
+ iterator insert(const_iterator pos, const_reference v) {
563
+ return emplace(pos, v);
564
+ }
565
+
566
+ // Overload of `InlinedVector::insert(...)` that inserts `v` at `pos` using
567
+ // move semantics, returning an `iterator` to the newly inserted element.
568
+ iterator insert(const_iterator pos, RValueReference v) {
569
+ return emplace(pos, std::move(v));
570
+ }
571
+
572
+ // Overload of `InlinedVector::insert(...)` that inserts `n` contiguous copies
573
+ // of `v` starting at `pos`, returning an `iterator` pointing to the first of
574
+ // the newly inserted elements.
575
+ iterator insert(const_iterator pos, size_type n, const_reference v) {
576
+ assert(pos >= begin());
577
+ assert(pos <= end());
578
+
579
+ if (ABSL_PREDICT_TRUE(n != 0)) {
580
+ value_type dealias = v;
581
+ return storage_.Insert(pos, CopyValueAdapter(dealias), n);
582
+ } else {
583
+ return const_cast<iterator>(pos);
584
+ }
585
+ }
586
+
587
+ // Overload of `InlinedVector::insert(...)` that inserts copies of the
588
+ // elements of `list` starting at `pos`, returning an `iterator` pointing to
589
+ // the first of the newly inserted elements.
590
+ iterator insert(const_iterator pos, std::initializer_list<value_type> list) {
591
+ return insert(pos, list.begin(), list.end());
592
+ }
593
+
594
+ // Overload of `InlinedVector::insert(...)` that inserts the range [`first`,
595
+ // `last`) starting at `pos`, returning an `iterator` pointing to the first
596
+ // of the newly inserted elements.
597
+ //
598
+ // NOTE: this overload is for iterators that are "forward" category or better.
599
+ template <typename ForwardIterator,
600
+ EnableIfAtLeastForwardIterator<ForwardIterator>* = nullptr>
601
+ iterator insert(const_iterator pos, ForwardIterator first,
602
+ ForwardIterator last) {
603
+ assert(pos >= begin());
604
+ assert(pos <= end());
605
+
606
+ if (ABSL_PREDICT_TRUE(first != last)) {
607
+ return storage_.Insert(pos, IteratorValueAdapter<ForwardIterator>(first),
608
+ std::distance(first, last));
609
+ } else {
610
+ return const_cast<iterator>(pos);
611
+ }
612
+ }
613
+
614
+ // Overload of `InlinedVector::insert(...)` that inserts the range [`first`,
615
+ // `last`) starting at `pos`, returning an `iterator` pointing to the first
616
+ // of the newly inserted elements.
617
+ //
618
+ // NOTE: this overload is for iterators that are "input" category.
619
+ template <typename InputIterator,
620
+ DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
621
+ iterator insert(const_iterator pos, InputIterator first, InputIterator last) {
622
+ assert(pos >= begin());
623
+ assert(pos <= end());
624
+
625
+ size_type index = std::distance(cbegin(), pos);
626
+ for (size_type i = index; first != last; ++i, static_cast<void>(++first)) {
627
+ insert(data() + i, *first);
628
+ }
629
+
630
+ return iterator(data() + index);
631
+ }
632
+
633
+ // `InlinedVector::emplace(...)`
634
+ //
635
+ // Constructs and inserts an element using `args...` in the inlined vector at
636
+ // `pos`, returning an `iterator` pointing to the newly emplaced element.
637
+ template <typename... Args>
638
+ iterator emplace(const_iterator pos, Args&&... args) {
639
+ assert(pos >= begin());
640
+ assert(pos <= end());
641
+
642
+ value_type dealias(std::forward<Args>(args)...);
643
+ return storage_.Insert(pos,
644
+ IteratorValueAdapter<MoveIterator>(
645
+ MoveIterator(std::addressof(dealias))),
646
+ 1);
647
+ }
648
+
649
+ // `InlinedVector::emplace_back(...)`
650
+ //
651
+ // Constructs and inserts an element using `args...` in the inlined vector at
652
+ // `end()`, returning a `reference` to the newly emplaced element.
653
+ template <typename... Args>
654
+ reference emplace_back(Args&&... args) {
655
+ return storage_.EmplaceBack(std::forward<Args>(args)...);
656
+ }
657
+
658
+ // `InlinedVector::push_back(...)`
659
+ //
660
+ // Inserts a copy of `v` in the inlined vector at `end()`.
661
+ void push_back(const_reference v) { static_cast<void>(emplace_back(v)); }
662
+
663
+ // Overload of `InlinedVector::push_back(...)` for inserting `v` at `end()`
664
+ // using move semantics.
665
+ void push_back(RValueReference v) {
666
+ static_cast<void>(emplace_back(std::move(v)));
667
+ }
668
+
669
+ // `InlinedVector::pop_back()`
670
+ //
671
+ // Destroys the element at `back()`, reducing the size by `1`.
672
+ void pop_back() noexcept {
673
+ assert(!empty());
674
+
675
+ AllocatorTraits::destroy(*storage_.GetAllocPtr(), data() + (size() - 1));
676
+ storage_.SubtractSize(1);
677
+ }
678
+
679
+ // `InlinedVector::erase(...)`
680
+ //
681
+ // Erases the element at `pos`, returning an `iterator` pointing to where the
682
+ // erased element was located.
683
+ //
684
+ // NOTE: may return `end()`, which is not dereferencable.
685
+ iterator erase(const_iterator pos) {
686
+ assert(pos >= begin());
687
+ assert(pos < end());
688
+
689
+ return storage_.Erase(pos, pos + 1);
690
+ }
691
+
692
+ // Overload of `InlinedVector::erase(...)` that erases every element in the
693
+ // range [`from`, `to`), returning an `iterator` pointing to where the first
694
+ // erased element was located.
695
+ //
696
+ // NOTE: may return `end()`, which is not dereferencable.
697
+ iterator erase(const_iterator from, const_iterator to) {
698
+ assert(from >= begin());
699
+ assert(from <= to);
700
+ assert(to <= end());
701
+
702
+ if (ABSL_PREDICT_TRUE(from != to)) {
703
+ return storage_.Erase(from, to);
704
+ } else {
705
+ return const_cast<iterator>(from);
706
+ }
707
+ }
708
+
709
+ // `InlinedVector::clear()`
710
+ //
711
+ // Destroys all elements in the inlined vector, setting the size to `0` and
712
+ // deallocating any held memory.
713
+ void clear() noexcept {
714
+ inlined_vector_internal::DestroyElements(storage_.GetAllocPtr(), data(),
715
+ size());
716
+ storage_.DeallocateIfAllocated();
717
+
718
+ storage_.SetInlinedSize(0);
719
+ }
720
+
721
+ // `InlinedVector::reserve(...)`
722
+ //
723
+ // Ensures that there is enough room for at least `n` elements.
724
+ void reserve(size_type n) { storage_.Reserve(n); }
725
+
726
+ // `InlinedVector::shrink_to_fit()`
727
+ //
728
+ // Reduces memory usage by freeing unused memory. After being called, calls to
729
+ // `capacity()` will be equal to `max(N, size())`.
730
+ //
731
+ // If `size() <= N` and the inlined vector contains allocated memory, the
732
+ // elements will all be moved to the inlined space and the allocated memory
733
+ // will be deallocated.
734
+ //
735
+ // If `size() > N` and `size() < capacity()`, the elements will be moved to a
736
+ // smaller allocation.
737
+ void shrink_to_fit() {
738
+ if (storage_.GetIsAllocated()) {
739
+ storage_.ShrinkToFit();
740
+ }
741
+ }
742
+
743
+ // `InlinedVector::swap(...)`
744
+ //
745
+ // Swaps the contents of the inlined vector with `other`.
746
+ void swap(InlinedVector& other) {
747
+ if (ABSL_PREDICT_TRUE(this != std::addressof(other))) {
748
+ storage_.Swap(std::addressof(other.storage_));
749
+ }
750
+ }
751
+
752
+ private:
753
+ template <typename H, typename TheT, size_t TheN, typename TheA>
754
+ friend H AbslHashValue(H h, const absl::InlinedVector<TheT, TheN, TheA>& a);
755
+
756
+ Storage storage_;
757
+ };
758
+
759
+ // -----------------------------------------------------------------------------
760
+ // InlinedVector Non-Member Functions
761
+ // -----------------------------------------------------------------------------
762
+
763
+ // `swap(...)`
764
+ //
765
+ // Swaps the contents of two inlined vectors.
766
+ template <typename T, size_t N, typename A>
767
+ void swap(absl::InlinedVector<T, N, A>& a,
768
+ absl::InlinedVector<T, N, A>& b) noexcept(noexcept(a.swap(b))) {
769
+ a.swap(b);
770
+ }
771
+
772
+ // `operator==(...)`
773
+ //
774
+ // Tests for value-equality of two inlined vectors.
775
+ template <typename T, size_t N, typename A>
776
+ bool operator==(const absl::InlinedVector<T, N, A>& a,
777
+ const absl::InlinedVector<T, N, A>& b) {
778
+ auto a_data = a.data();
779
+ auto b_data = b.data();
780
+ return absl::equal(a_data, a_data + a.size(), b_data, b_data + b.size());
781
+ }
782
+
783
+ // `operator!=(...)`
784
+ //
785
+ // Tests for value-inequality of two inlined vectors.
786
+ template <typename T, size_t N, typename A>
787
+ bool operator!=(const absl::InlinedVector<T, N, A>& a,
788
+ const absl::InlinedVector<T, N, A>& b) {
789
+ return !(a == b);
790
+ }
791
+
792
+ // `operator<(...)`
793
+ //
794
+ // Tests whether the value of an inlined vector is less than the value of
795
+ // another inlined vector using a lexicographical comparison algorithm.
796
+ template <typename T, size_t N, typename A>
797
+ bool operator<(const absl::InlinedVector<T, N, A>& a,
798
+ const absl::InlinedVector<T, N, A>& b) {
799
+ auto a_data = a.data();
800
+ auto b_data = b.data();
801
+ return std::lexicographical_compare(a_data, a_data + a.size(), b_data,
802
+ b_data + b.size());
803
+ }
804
+
805
+ // `operator>(...)`
806
+ //
807
+ // Tests whether the value of an inlined vector is greater than the value of
808
+ // another inlined vector using a lexicographical comparison algorithm.
809
+ template <typename T, size_t N, typename A>
810
+ bool operator>(const absl::InlinedVector<T, N, A>& a,
811
+ const absl::InlinedVector<T, N, A>& b) {
812
+ return b < a;
813
+ }
814
+
815
+ // `operator<=(...)`
816
+ //
817
+ // Tests whether the value of an inlined vector is less than or equal to the
818
+ // value of another inlined vector using a lexicographical comparison algorithm.
819
+ template <typename T, size_t N, typename A>
820
+ bool operator<=(const absl::InlinedVector<T, N, A>& a,
821
+ const absl::InlinedVector<T, N, A>& b) {
822
+ return !(b < a);
823
+ }
824
+
825
+ // `operator>=(...)`
826
+ //
827
+ // Tests whether the value of an inlined vector is greater than or equal to the
828
+ // value of another inlined vector using a lexicographical comparison algorithm.
829
+ template <typename T, size_t N, typename A>
830
+ bool operator>=(const absl::InlinedVector<T, N, A>& a,
831
+ const absl::InlinedVector<T, N, A>& b) {
832
+ return !(a < b);
833
+ }
834
+
835
+ // `AbslHashValue(...)`
836
+ //
837
+ // Provides `absl::Hash` support for `absl::InlinedVector`. It is uncommon to
838
+ // call this directly.
839
+ template <typename H, typename T, size_t N, typename A>
840
+ H AbslHashValue(H h, const absl::InlinedVector<T, N, A>& a) {
841
+ auto size = a.size();
842
+ return H::combine(H::combine_contiguous(std::move(h), a.data(), size), size);
843
+ }
844
+
845
+ ABSL_NAMESPACE_END
846
+ } // namespace absl
847
+
848
+ #endif // ABSL_CONTAINER_INLINED_VECTOR_H_