re2 1.24.0 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/LICENSE +15 -20
  2. package/README.md +63 -4
  3. package/binding.gyp +1 -2
  4. package/lib/addon.cc +9 -5
  5. package/lib/exec.cc +4 -4
  6. package/lib/match.cc +4 -4
  7. package/lib/new.cc +6 -6
  8. package/lib/pattern.cc +148 -1
  9. package/lib/replace.cc +5 -4
  10. package/lib/search.cc +1 -1
  11. package/lib/set.cc +85 -10
  12. package/lib/test.cc +1 -1
  13. package/lib/unicode_properties.h +15840 -0
  14. package/lib/wrapped_re2.h +40 -4
  15. package/lib/wrapped_re2_set.h +3 -1
  16. package/llms-full.txt +497 -0
  17. package/llms.txt +135 -0
  18. package/package.json +19 -11
  19. package/re2.d.ts +2 -0
  20. package/re2.js +1 -0
  21. package/vendor/abseil-cpp/CMake/AbseilDll.cmake +87 -74
  22. package/vendor/abseil-cpp/CMakeLists.txt +3 -3
  23. package/vendor/abseil-cpp/FAQ.md +130 -79
  24. package/vendor/abseil-cpp/MODULE.bazel +6 -7
  25. package/vendor/abseil-cpp/absl/BUILD.bazel +6 -0
  26. package/vendor/abseil-cpp/absl/algorithm/BUILD.bazel +4 -0
  27. package/vendor/abseil-cpp/absl/algorithm/CMakeLists.txt +4 -0
  28. package/vendor/abseil-cpp/absl/algorithm/algorithm.h +34 -2
  29. package/vendor/abseil-cpp/absl/algorithm/container.h +164 -17
  30. package/vendor/abseil-cpp/absl/algorithm/container_test.cc +390 -13
  31. package/vendor/abseil-cpp/absl/base/BUILD.bazel +53 -6
  32. package/vendor/abseil-cpp/absl/base/CMakeLists.txt +28 -4
  33. package/vendor/abseil-cpp/absl/base/attributes.h +61 -42
  34. package/vendor/abseil-cpp/absl/base/call_once.h +1 -0
  35. package/vendor/abseil-cpp/absl/base/casts.h +8 -1
  36. package/vendor/abseil-cpp/absl/base/casts_test.cc +3 -6
  37. package/vendor/abseil-cpp/absl/base/config.h +53 -9
  38. package/vendor/abseil-cpp/absl/base/exception_safety_testing_test.cc +9 -9
  39. package/vendor/abseil-cpp/absl/base/fast_type_id.h +30 -2
  40. package/vendor/abseil-cpp/absl/base/fast_type_id_test.cc +3 -0
  41. package/vendor/abseil-cpp/absl/base/internal/exception_safety_testing.h +15 -12
  42. package/vendor/abseil-cpp/absl/base/internal/hardening.h +136 -0
  43. package/vendor/abseil-cpp/absl/base/internal/hardening_test.cc +168 -0
  44. package/vendor/abseil-cpp/absl/base/internal/iterator_traits.h +2 -2
  45. package/vendor/abseil-cpp/absl/base/internal/low_level_alloc.cc +6 -0
  46. package/vendor/abseil-cpp/absl/base/internal/low_level_scheduling.h +77 -15
  47. package/vendor/abseil-cpp/absl/base/internal/sysinfo.cc +1 -2
  48. package/vendor/abseil-cpp/absl/base/internal/thread_identity.h +52 -0
  49. package/vendor/abseil-cpp/absl/base/internal/unscaledcycleclock.h +5 -0
  50. package/vendor/abseil-cpp/absl/base/macros.h +36 -20
  51. package/vendor/abseil-cpp/absl/base/nullability.h +4 -3
  52. package/vendor/abseil-cpp/absl/base/optimization.h +3 -2
  53. package/vendor/abseil-cpp/absl/base/optimization_test.cc +4 -3
  54. package/vendor/abseil-cpp/absl/base/options.h +55 -1
  55. package/vendor/abseil-cpp/absl/base/policy_checks.h +5 -5
  56. package/vendor/abseil-cpp/absl/base/{internal/throw_delegate.cc → throw_delegate.cc} +9 -7
  57. package/vendor/abseil-cpp/absl/base/{internal/throw_delegate.h → throw_delegate.h} +4 -14
  58. package/vendor/abseil-cpp/absl/base/throw_delegate_test.cc +19 -28
  59. package/vendor/abseil-cpp/absl/cleanup/BUILD.bazel +2 -0
  60. package/vendor/abseil-cpp/absl/cleanup/CMakeLists.txt +2 -0
  61. package/vendor/abseil-cpp/absl/cleanup/cleanup.h +3 -2
  62. package/vendor/abseil-cpp/absl/cleanup/internal/cleanup.h +3 -2
  63. package/vendor/abseil-cpp/absl/container/BUILD.bazel +19 -7
  64. package/vendor/abseil-cpp/absl/container/CMakeLists.txt +6 -5
  65. package/vendor/abseil-cpp/absl/container/btree_benchmark.cc +3 -5
  66. package/vendor/abseil-cpp/absl/container/btree_set.h +5 -5
  67. package/vendor/abseil-cpp/absl/container/btree_test.cc +11 -14
  68. package/vendor/abseil-cpp/absl/container/chunked_queue.h +8 -6
  69. package/vendor/abseil-cpp/absl/container/chunked_queue_test.cc +5 -5
  70. package/vendor/abseil-cpp/absl/container/fixed_array.h +14 -13
  71. package/vendor/abseil-cpp/absl/container/fixed_array_test.cc +3 -3
  72. package/vendor/abseil-cpp/absl/container/flat_hash_map.h +18 -6
  73. package/vendor/abseil-cpp/absl/container/flat_hash_map_test.cc +34 -1
  74. package/vendor/abseil-cpp/absl/container/flat_hash_set.h +21 -7
  75. package/vendor/abseil-cpp/absl/container/flat_hash_set_test.cc +39 -7
  76. package/vendor/abseil-cpp/absl/container/inlined_vector.h +29 -29
  77. package/vendor/abseil-cpp/absl/container/inlined_vector_test.cc +2 -2
  78. package/vendor/abseil-cpp/absl/container/internal/btree.h +32 -24
  79. package/vendor/abseil-cpp/absl/container/internal/btree_container.h +16 -17
  80. package/vendor/abseil-cpp/absl/container/internal/common.h +6 -5
  81. package/vendor/abseil-cpp/absl/container/internal/common_policy_traits.h +1 -1
  82. package/vendor/abseil-cpp/absl/container/internal/compressed_tuple.h +16 -16
  83. package/vendor/abseil-cpp/absl/container/internal/compressed_tuple_test.cc +13 -13
  84. package/vendor/abseil-cpp/absl/container/internal/container_memory.h +41 -31
  85. package/vendor/abseil-cpp/absl/container/internal/hash_function_defaults.h +2 -2
  86. package/vendor/abseil-cpp/absl/container/internal/hash_generator_testing.h +4 -4
  87. package/vendor/abseil-cpp/absl/container/internal/hash_policy_traits.h +3 -3
  88. package/vendor/abseil-cpp/absl/container/internal/hashtable_control_bytes.h +27 -19
  89. package/vendor/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +2 -2
  90. package/vendor/abseil-cpp/absl/container/internal/hashtablez_sampler.h +0 -17
  91. package/vendor/abseil-cpp/absl/container/internal/hashtablez_sampler_test.cc +12 -30
  92. package/vendor/abseil-cpp/absl/container/internal/inlined_vector.h +28 -28
  93. package/vendor/abseil-cpp/absl/container/internal/layout.h +13 -13
  94. package/vendor/abseil-cpp/absl/container/internal/layout_test.cc +3 -2
  95. package/vendor/abseil-cpp/absl/container/internal/raw_hash_map.h +60 -62
  96. package/vendor/abseil-cpp/absl/container/internal/raw_hash_set.cc +59 -39
  97. package/vendor/abseil-cpp/absl/container/internal/raw_hash_set.h +619 -326
  98. package/vendor/abseil-cpp/absl/container/internal/raw_hash_set_benchmark.cc +25 -2
  99. package/vendor/abseil-cpp/absl/container/internal/raw_hash_set_probe_benchmark.cc +4 -4
  100. package/vendor/abseil-cpp/absl/container/internal/raw_hash_set_test.cc +575 -159
  101. package/vendor/abseil-cpp/absl/container/linked_hash_map.h +2 -2
  102. package/vendor/abseil-cpp/absl/container/node_hash_map.h +27 -15
  103. package/vendor/abseil-cpp/absl/container/node_hash_map_test.cc +34 -0
  104. package/vendor/abseil-cpp/absl/container/node_hash_set.h +25 -11
  105. package/vendor/abseil-cpp/absl/container/node_hash_set_test.cc +39 -7
  106. package/vendor/abseil-cpp/absl/container/sample_element_size_test.cc +7 -4
  107. package/vendor/abseil-cpp/absl/crc/BUILD.bazel +0 -1
  108. package/vendor/abseil-cpp/absl/crc/CMakeLists.txt +2 -3
  109. package/vendor/abseil-cpp/absl/crc/crc32c_benchmark.cc +2 -1
  110. package/vendor/abseil-cpp/absl/crc/internal/cpu_detect.cc +6 -6
  111. package/vendor/abseil-cpp/absl/crc/internal/crc.cc +4 -6
  112. package/vendor/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +41 -0
  113. package/vendor/abseil-cpp/absl/crc/internal/crc_internal.h +0 -16
  114. package/vendor/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +143 -81
  115. package/vendor/abseil-cpp/absl/debugging/BUILD.bazel +9 -31
  116. package/vendor/abseil-cpp/absl/debugging/CMakeLists.txt +3 -33
  117. package/vendor/abseil-cpp/absl/debugging/internal/demangle_rust.h +8 -0
  118. package/vendor/abseil-cpp/absl/debugging/internal/demangle_test.cc +2 -1
  119. package/vendor/abseil-cpp/absl/debugging/internal/examine_stack.cc +12 -2
  120. package/vendor/abseil-cpp/absl/debugging/internal/examine_stack.h +2 -3
  121. package/vendor/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +11 -0
  122. package/vendor/abseil-cpp/absl/debugging/internal/stacktrace_emscripten-inl.inc +13 -4
  123. package/vendor/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +14 -7
  124. package/vendor/abseil-cpp/absl/debugging/internal/stacktrace_riscv-inl.inc +4 -0
  125. package/vendor/abseil-cpp/absl/debugging/internal/symbolize.h +46 -36
  126. package/vendor/abseil-cpp/absl/debugging/stacktrace.cc +18 -58
  127. package/vendor/abseil-cpp/absl/debugging/stacktrace.h +5 -48
  128. package/vendor/abseil-cpp/absl/debugging/stacktrace_test.cc +10 -124
  129. package/vendor/abseil-cpp/absl/debugging/symbolize.cc +20 -2
  130. package/vendor/abseil-cpp/absl/debugging/symbolize_elf.inc +58 -106
  131. package/vendor/abseil-cpp/absl/debugging/symbolize_test.cc +37 -36
  132. package/vendor/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +4 -4
  133. package/vendor/abseil-cpp/absl/flags/BUILD.bazel +6 -3
  134. package/vendor/abseil-cpp/absl/flags/CMakeLists.txt +1 -1
  135. package/vendor/abseil-cpp/absl/flags/commandlineflag.h +8 -6
  136. package/vendor/abseil-cpp/absl/flags/commandlineflag_test.cc +1 -1
  137. package/vendor/abseil-cpp/absl/flags/flag_benchmark.cc +5 -5
  138. package/vendor/abseil-cpp/absl/flags/flag_test.cc +30 -30
  139. package/vendor/abseil-cpp/absl/flags/internal/flag.cc +4 -4
  140. package/vendor/abseil-cpp/absl/flags/internal/flag.h +6 -6
  141. package/vendor/abseil-cpp/absl/flags/marshalling.h +2 -28
  142. package/vendor/abseil-cpp/absl/flags/marshalling_test.cc +12 -11
  143. package/vendor/abseil-cpp/absl/flags/reflection_test.cc +1 -1
  144. package/vendor/abseil-cpp/absl/functional/BUILD.bazel +26 -1
  145. package/vendor/abseil-cpp/absl/functional/CMakeLists.txt +29 -1
  146. package/vendor/abseil-cpp/absl/functional/any_invocable.h +13 -14
  147. package/vendor/abseil-cpp/absl/functional/any_invocable_test.cc +46 -47
  148. package/vendor/abseil-cpp/absl/functional/bind_back.h +79 -0
  149. package/vendor/abseil-cpp/absl/functional/bind_back_test.cc +237 -0
  150. package/vendor/abseil-cpp/absl/functional/bind_front.h +7 -1
  151. package/vendor/abseil-cpp/absl/functional/bind_front_test.cc +4 -4
  152. package/vendor/abseil-cpp/absl/functional/function_ref_test.cc +2 -2
  153. package/vendor/abseil-cpp/absl/functional/internal/any_invocable.h +28 -28
  154. package/vendor/abseil-cpp/absl/functional/internal/back_binder.h +95 -0
  155. package/vendor/abseil-cpp/absl/functional/internal/front_binder.h +4 -4
  156. package/vendor/abseil-cpp/absl/functional/internal/function_ref.h +2 -2
  157. package/vendor/abseil-cpp/absl/functional/overload_test.cc +13 -13
  158. package/vendor/abseil-cpp/absl/hash/BUILD.bazel +1 -2
  159. package/vendor/abseil-cpp/absl/hash/CMakeLists.txt +1 -2
  160. package/vendor/abseil-cpp/absl/hash/hash.h +1 -1
  161. package/vendor/abseil-cpp/absl/hash/hash_test.cc +14 -20
  162. package/vendor/abseil-cpp/absl/hash/hash_testing.h +11 -9
  163. package/vendor/abseil-cpp/absl/hash/internal/city.cc +39 -51
  164. package/vendor/abseil-cpp/absl/hash/internal/hash.cc +165 -47
  165. package/vendor/abseil-cpp/absl/hash/internal/hash.h +86 -27
  166. package/vendor/abseil-cpp/absl/hash/internal/low_level_hash_test.cc +36 -1
  167. package/vendor/abseil-cpp/absl/hash/internal/spy_hash_state.h +8 -5
  168. package/vendor/abseil-cpp/absl/log/BUILD.bazel +5 -2
  169. package/vendor/abseil-cpp/absl/log/CMakeLists.txt +5 -3
  170. package/vendor/abseil-cpp/absl/log/absl_vlog_is_on.h +0 -2
  171. package/vendor/abseil-cpp/absl/log/internal/BUILD.bazel +15 -1
  172. package/vendor/abseil-cpp/absl/log/internal/log_message.cc +5 -4
  173. package/vendor/abseil-cpp/absl/log/internal/log_message.h +14 -0
  174. package/vendor/abseil-cpp/absl/log/internal/nullstream.h +1 -1
  175. package/vendor/abseil-cpp/absl/log/internal/proto.cc +13 -0
  176. package/vendor/abseil-cpp/absl/log/internal/structured_proto.cc +5 -5
  177. package/vendor/abseil-cpp/absl/log/internal/structured_proto.h +6 -5
  178. package/vendor/abseil-cpp/absl/log/internal/structured_proto_test.cc +3 -3
  179. package/vendor/abseil-cpp/absl/log/internal/vlog_config.cc +2 -2
  180. package/vendor/abseil-cpp/absl/log/internal/vlog_config_benchmark.cc +3 -3
  181. package/vendor/abseil-cpp/absl/log/log_format_test.cc +19 -2
  182. package/vendor/abseil-cpp/absl/log/log_modifier_methods_test.cc +18 -0
  183. package/vendor/abseil-cpp/absl/log/log_streamer.h +29 -2
  184. package/vendor/abseil-cpp/absl/log/log_streamer_test.cc +18 -0
  185. package/vendor/abseil-cpp/absl/log/scoped_mock_log_test.cc +1 -1
  186. package/vendor/abseil-cpp/absl/log/vlog_is_on.h +0 -2
  187. package/vendor/abseil-cpp/absl/log/vlog_is_on_test.cc +6 -5
  188. package/vendor/abseil-cpp/absl/memory/memory.h +55 -5
  189. package/vendor/abseil-cpp/absl/memory/memory_test.cc +55 -1
  190. package/vendor/abseil-cpp/absl/meta/BUILD.bazel +2 -0
  191. package/vendor/abseil-cpp/absl/meta/internal/requires.h +1 -1
  192. package/vendor/abseil-cpp/absl/meta/type_traits.h +119 -55
  193. package/vendor/abseil-cpp/absl/meta/type_traits_test.cc +7 -7
  194. package/vendor/abseil-cpp/absl/numeric/int128_test.cc +6 -6
  195. package/vendor/abseil-cpp/absl/profiling/BUILD.bazel +3 -1
  196. package/vendor/abseil-cpp/absl/profiling/hashtable.cc +0 -4
  197. package/vendor/abseil-cpp/absl/profiling/internal/profile_builder.cc +32 -33
  198. package/vendor/abseil-cpp/absl/profiling/internal/profile_builder.h +25 -2
  199. package/vendor/abseil-cpp/absl/profiling/internal/sample_recorder_test.cc +8 -5
  200. package/vendor/abseil-cpp/absl/random/BUILD.bazel +13 -1
  201. package/vendor/abseil-cpp/absl/random/CMakeLists.txt +23 -2
  202. package/vendor/abseil-cpp/absl/random/benchmarks.cc +1 -1
  203. package/vendor/abseil-cpp/absl/random/beta_distribution.h +2 -2
  204. package/vendor/abseil-cpp/absl/random/bit_gen_ref.h +26 -53
  205. package/vendor/abseil-cpp/absl/random/bit_gen_ref_test.cc +43 -0
  206. package/vendor/abseil-cpp/absl/random/discrete_distribution.h +1 -1
  207. package/vendor/abseil-cpp/absl/random/distributions.h +17 -17
  208. package/vendor/abseil-cpp/absl/random/distributions_test.cc +4 -4
  209. package/vendor/abseil-cpp/absl/random/exponential_distribution.h +1 -1
  210. package/vendor/abseil-cpp/absl/random/internal/BUILD.bazel +4 -2
  211. package/vendor/abseil-cpp/absl/random/internal/distribution_caller.h +8 -21
  212. package/vendor/abseil-cpp/absl/random/internal/fast_uniform_bits.h +1 -1
  213. package/vendor/abseil-cpp/absl/random/internal/generate_real.h +1 -1
  214. package/vendor/abseil-cpp/absl/random/internal/iostream_state_saver.h +2 -2
  215. package/vendor/abseil-cpp/absl/random/internal/iostream_state_saver_test.cc +3 -2
  216. package/vendor/abseil-cpp/absl/random/internal/mock_helpers.h +14 -40
  217. package/vendor/abseil-cpp/absl/random/internal/nonsecure_base.h +2 -2
  218. package/vendor/abseil-cpp/absl/random/internal/nonsecure_base_test.cc +2 -2
  219. package/vendor/abseil-cpp/absl/random/internal/pcg_engine.h +6 -6
  220. package/vendor/abseil-cpp/absl/random/internal/pcg_engine_test.cc +3 -2
  221. package/vendor/abseil-cpp/absl/random/internal/randen_detect.cc +6 -6
  222. package/vendor/abseil-cpp/absl/random/internal/randen_engine.h +2 -2
  223. package/vendor/abseil-cpp/absl/random/internal/randen_engine_test.cc +3 -2
  224. package/vendor/abseil-cpp/absl/random/internal/randen_test.cc +3 -2
  225. package/vendor/abseil-cpp/absl/random/internal/salted_seed_seq.h +6 -5
  226. package/vendor/abseil-cpp/absl/random/internal/seed_material.cc +4 -4
  227. package/vendor/abseil-cpp/absl/random/internal/seed_material.h +2 -1
  228. package/vendor/abseil-cpp/absl/random/internal/traits.h +21 -0
  229. package/vendor/abseil-cpp/absl/random/internal/traits_test.cc +5 -0
  230. package/vendor/abseil-cpp/absl/random/internal/uniform_helper.h +23 -23
  231. package/vendor/abseil-cpp/absl/random/internal/uniform_helper_test.cc +2 -1
  232. package/vendor/abseil-cpp/absl/random/mocking_access.h +74 -0
  233. package/vendor/abseil-cpp/absl/random/mocking_bit_gen.h +9 -19
  234. package/vendor/abseil-cpp/absl/random/uniform_real_distribution.h +1 -1
  235. package/vendor/abseil-cpp/absl/status/BUILD.bazel +81 -0
  236. package/vendor/abseil-cpp/absl/status/CMakeLists.txt +91 -0
  237. package/vendor/abseil-cpp/absl/status/internal/status_internal.cc +63 -18
  238. package/vendor/abseil-cpp/absl/status/internal/status_internal.h +26 -2
  239. package/vendor/abseil-cpp/absl/status/internal/status_matchers.h +22 -8
  240. package/vendor/abseil-cpp/absl/status/internal/statusor_internal.h +43 -43
  241. package/vendor/abseil-cpp/absl/status/status.cc +62 -70
  242. package/vendor/abseil-cpp/absl/status/status.h +249 -23
  243. package/vendor/abseil-cpp/absl/status/status_benchmark.cc +12 -0
  244. package/vendor/abseil-cpp/absl/status/status_builder.cc +196 -0
  245. package/vendor/abseil-cpp/absl/status/status_builder.h +978 -0
  246. package/vendor/abseil-cpp/absl/status/status_builder_test.cc +380 -0
  247. package/vendor/abseil-cpp/absl/status/status_macros.h +484 -0
  248. package/vendor/abseil-cpp/absl/status/status_macros_test.cc +634 -0
  249. package/vendor/abseil-cpp/absl/status/status_matchers.h +2 -1
  250. package/vendor/abseil-cpp/absl/status/status_matchers_test.cc +3 -4
  251. package/vendor/abseil-cpp/absl/status/status_payload_printer.h +3 -2
  252. package/vendor/abseil-cpp/absl/status/status_test.cc +443 -13
  253. package/vendor/abseil-cpp/absl/status/statusor.h +69 -36
  254. package/vendor/abseil-cpp/absl/status/statusor_test.cc +132 -35
  255. package/vendor/abseil-cpp/absl/strings/BUILD.bazel +42 -7
  256. package/vendor/abseil-cpp/absl/strings/CMakeLists.txt +33 -4
  257. package/vendor/abseil-cpp/absl/strings/ascii.h +1 -2
  258. package/vendor/abseil-cpp/absl/strings/atod_manual_test.cc +5 -5
  259. package/vendor/abseil-cpp/absl/strings/cord.cc +26 -7
  260. package/vendor/abseil-cpp/absl/strings/cord.h +23 -13
  261. package/vendor/abseil-cpp/absl/strings/cord_buffer.h +4 -2
  262. package/vendor/abseil-cpp/absl/strings/cord_test.cc +85 -9
  263. package/vendor/abseil-cpp/absl/strings/escaping.cc +183 -35
  264. package/vendor/abseil-cpp/absl/strings/escaping.h +12 -2
  265. package/vendor/abseil-cpp/absl/strings/escaping_benchmark.cc +1 -3
  266. package/vendor/abseil-cpp/absl/strings/escaping_test.cc +22 -18
  267. package/vendor/abseil-cpp/absl/strings/has_absl_stringify_test.cc +2 -2
  268. package/vendor/abseil-cpp/absl/strings/has_ostream_operator_test.cc +2 -2
  269. package/vendor/abseil-cpp/absl/strings/internal/append_and_overwrite.h +10 -10
  270. package/vendor/abseil-cpp/absl/strings/internal/cordz_sample_token_test.cc +1 -1
  271. package/vendor/abseil-cpp/absl/strings/internal/damerau_levenshtein_distance.cc +6 -0
  272. package/vendor/abseil-cpp/absl/strings/internal/damerau_levenshtein_distance.h +1 -0
  273. package/vendor/abseil-cpp/absl/strings/internal/escaping.cc +0 -141
  274. package/vendor/abseil-cpp/absl/strings/internal/escaping.h +2 -26
  275. package/vendor/abseil-cpp/absl/strings/internal/generic_printer_internal.h +23 -2
  276. package/vendor/abseil-cpp/absl/strings/internal/generic_printer_test.cc +6 -2
  277. package/vendor/abseil-cpp/absl/strings/internal/resize_uninitialized.h +31 -24
  278. package/vendor/abseil-cpp/absl/strings/internal/resize_uninitialized_test.cc +16 -41
  279. package/vendor/abseil-cpp/absl/strings/internal/stl_type_traits.h +39 -39
  280. package/vendor/abseil-cpp/absl/strings/internal/str_format/arg.h +14 -22
  281. package/vendor/abseil-cpp/absl/strings/internal/str_format/bind.h +2 -2
  282. package/vendor/abseil-cpp/absl/strings/internal/str_format/convert_test.cc +12 -20
  283. package/vendor/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +510 -307
  284. package/vendor/abseil-cpp/absl/strings/internal/str_join_internal.h +0 -1
  285. package/vendor/abseil-cpp/absl/strings/internal/str_split_internal.h +9 -10
  286. package/vendor/abseil-cpp/absl/strings/internal/string_constant_test.cc +6 -5
  287. package/vendor/abseil-cpp/absl/strings/internal/stringify_sink.h +12 -0
  288. package/vendor/abseil-cpp/absl/strings/internal/stringify_stream.h +119 -0
  289. package/vendor/abseil-cpp/absl/strings/internal/stringify_stream_test.cc +111 -0
  290. package/vendor/abseil-cpp/absl/strings/numbers.cc +406 -0
  291. package/vendor/abseil-cpp/absl/strings/numbers.h +4 -0
  292. package/vendor/abseil-cpp/absl/strings/numbers_test.cc +33 -0
  293. package/vendor/abseil-cpp/absl/strings/resize_and_overwrite.h +10 -6
  294. package/vendor/abseil-cpp/absl/strings/str_cat.h +36 -1
  295. package/vendor/abseil-cpp/absl/strings/str_cat_benchmark.cc +1 -2
  296. package/vendor/abseil-cpp/absl/strings/str_cat_test.cc +28 -0
  297. package/vendor/abseil-cpp/absl/strings/str_join_test.cc +4 -4
  298. package/vendor/abseil-cpp/absl/strings/str_split.h +11 -6
  299. package/vendor/abseil-cpp/absl/strings/str_split_test.cc +13 -0
  300. package/vendor/abseil-cpp/absl/strings/substitute.h +2 -2
  301. package/vendor/abseil-cpp/absl/synchronization/BUILD.bazel +3 -0
  302. package/vendor/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +21 -0
  303. package/vendor/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +5 -0
  304. package/vendor/abseil-cpp/absl/synchronization/mutex.cc +13 -0
  305. package/vendor/abseil-cpp/absl/synchronization/mutex.h +32 -2
  306. package/vendor/abseil-cpp/absl/synchronization/mutex_test.cc +17 -3
  307. package/vendor/abseil-cpp/absl/time/BUILD.bazel +80 -0
  308. package/vendor/abseil-cpp/absl/time/CMakeLists.txt +73 -0
  309. package/vendor/abseil-cpp/absl/time/clock.h +3 -0
  310. package/vendor/abseil-cpp/absl/time/clock_interface.cc +71 -0
  311. package/vendor/abseil-cpp/absl/time/clock_interface.h +93 -0
  312. package/vendor/abseil-cpp/absl/time/clock_interface_test.cc +128 -0
  313. package/vendor/abseil-cpp/absl/time/format.cc +3 -10
  314. package/vendor/abseil-cpp/absl/time/format_test.cc +12 -0
  315. package/vendor/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +90 -89
  316. package/vendor/abseil-cpp/absl/time/internal/cctz/src/time_zone_format_test.cc +80 -5
  317. package/vendor/abseil-cpp/absl/time/internal/cctz/src/time_zone_name_win.cc +1 -2
  318. package/vendor/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +10 -15
  319. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/version +1 -1
  320. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Vancouver +0 -0
  321. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Asia/Ho_Chi_Minh +0 -0
  322. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Asia/Phnom_Penh +0 -0
  323. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Asia/Saigon +0 -0
  324. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Asia/Tbilisi +0 -0
  325. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Asia/Vientiane +0 -0
  326. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Canada/Pacific +0 -0
  327. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Europe/Chisinau +0 -0
  328. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/Europe/Tiraspol +0 -0
  329. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/zone1970.tab +1 -1
  330. package/vendor/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/zonenow.tab +3 -3
  331. package/vendor/abseil-cpp/absl/time/simulated_clock.cc +225 -0
  332. package/vendor/abseil-cpp/absl/time/simulated_clock.h +109 -0
  333. package/vendor/abseil-cpp/absl/time/simulated_clock_test.cc +614 -0
  334. package/vendor/abseil-cpp/absl/types/BUILD.bazel +116 -0
  335. package/vendor/abseil-cpp/absl/types/CMakeLists.txt +100 -0
  336. package/vendor/abseil-cpp/absl/types/any.h +26 -4
  337. package/vendor/abseil-cpp/absl/types/any_span.h +1067 -0
  338. package/vendor/abseil-cpp/absl/types/any_span_benchmark.cc +258 -0
  339. package/vendor/abseil-cpp/absl/types/any_span_test.cc +1210 -0
  340. package/vendor/abseil-cpp/absl/types/compare.h +4 -4
  341. package/vendor/abseil-cpp/absl/types/internal/any_span.h +477 -0
  342. package/vendor/abseil-cpp/absl/types/internal/span.h +5 -6
  343. package/vendor/abseil-cpp/absl/types/optional.h +30 -3
  344. package/vendor/abseil-cpp/absl/types/optional_ref.h +295 -0
  345. package/vendor/abseil-cpp/absl/types/optional_ref_test.cc +370 -0
  346. package/vendor/abseil-cpp/absl/types/source_location.cc +18 -0
  347. package/vendor/abseil-cpp/absl/types/source_location.h +172 -0
  348. package/vendor/abseil-cpp/absl/types/source_location_test.cc +139 -0
  349. package/vendor/abseil-cpp/absl/types/span.h +19 -23
  350. package/vendor/abseil-cpp/absl/types/variant.h +75 -18
  351. package/vendor/abseil-cpp/absl/types/variant_test.cc +23 -23
  352. package/vendor/abseil-cpp/absl/utility/BUILD.bazel +1 -0
  353. package/vendor/abseil-cpp/absl/utility/CMakeLists.txt +1 -0
  354. package/vendor/abseil-cpp/absl/utility/utility.h +99 -16
  355. package/vendor/abseil-cpp/ci/absl_alternate_options.h +2 -0
  356. package/vendor/abseil-cpp/ci/linux_arm_clang-latest_libcxx_bazel.sh +10 -4
  357. package/vendor/abseil-cpp/ci/linux_clang-latest_libcxx_asan_bazel.sh +13 -6
  358. package/vendor/abseil-cpp/ci/linux_clang-latest_libcxx_bazel.sh +10 -4
  359. package/vendor/abseil-cpp/ci/linux_clang-latest_libcxx_tsan_bazel.sh +12 -5
  360. package/vendor/abseil-cpp/ci/linux_clang-latest_libstdcxx_bazel.sh +9 -2
  361. package/vendor/abseil-cpp/ci/linux_docker_containers.sh +4 -4
  362. package/vendor/abseil-cpp/ci/linux_gcc-floor_libstdcxx_bazel.sh +10 -3
  363. package/vendor/abseil-cpp/ci/linux_gcc-latest_libstdcxx_bazel.sh +8 -2
  364. package/vendor/abseil-cpp/ci/macos_xcode_bazel.sh +4 -3
  365. package/vendor/abseil-cpp/ci/macos_xcode_cmake.sh +2 -2
  366. package/vendor/abseil-cpp/ci/windows_clangcl_bazel.bat +1 -1
  367. package/vendor/abseil-cpp/ci/windows_msvc_bazel.bat +1 -1
  368. package/vendor/abseil-cpp/absl/debugging/internal/borrowed_fixup_buffer.cc +0 -118
  369. package/vendor/abseil-cpp/absl/debugging/internal/borrowed_fixup_buffer.h +0 -71
  370. package/vendor/abseil-cpp/absl/debugging/internal/borrowed_fixup_buffer_test.cc +0 -97
@@ -0,0 +1,978 @@
1
+ // Copyright 2026 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: status_builder.h
17
+ // -----------------------------------------------------------------------------
18
+
19
+ #ifndef ABSL_STATUS_STATUS_BUILDER_H_
20
+ #define ABSL_STATUS_STATUS_BUILDER_H_
21
+
22
+ #include <memory>
23
+ #include <optional>
24
+ #include <ostream>
25
+ #include <string>
26
+ #include <type_traits>
27
+ #include <utility>
28
+
29
+ #include "absl/base/attributes.h"
30
+ #include "absl/base/config.h"
31
+ #include "absl/base/log_severity.h"
32
+ #include "absl/base/optimization.h"
33
+ #include "absl/status/status.h"
34
+ #include "absl/strings/cord.h"
35
+ #include "absl/strings/internal/ostringstream.h"
36
+ #include "absl/strings/internal/stringify_stream.h"
37
+ #include "absl/strings/string_view.h"
38
+ #include "absl/time/time.h"
39
+ #include "absl/types/source_location.h"
40
+
41
+ namespace absl {
42
+ ABSL_NAMESPACE_BEGIN
43
+
44
+ class LogSink;
45
+ class StatusBuilder;
46
+
47
+ namespace status_internal {
48
+
49
+ // StatusBuilder's operator<< overloads use an AbslStringifyStream to allow us
50
+ // to use AbslStringify. This wraps (but does not own) an OStringStream, which
51
+ // we use for speed. We bundle them together in Stream here, partly for
52
+ // convenience in StatusBuilder's implementation, and partly to help make sure
53
+ // their lifetimes are managed correctly.
54
+ class Stream {
55
+ public:
56
+ explicit Stream(std::string& message)
57
+ : ostringstream_(&message), absl_stringify_stream_(ostringstream_) {}
58
+
59
+ template <typename T>
60
+ friend Stream& operator<<(Stream& stream, const T& t) {
61
+ stream.absl_stringify_stream_ << t;
62
+ return stream;
63
+ }
64
+
65
+ private:
66
+ absl::strings_internal::OStringStream ostringstream_;
67
+ absl::strings_internal::StringifyStream absl_stringify_stream_;
68
+ };
69
+
70
+ // StatusBuilder::With() adaptors can be classified as either "pure policy" or
71
+ // "terminal". Terminal adaptors are a mix of "side effect" or "conversion".
72
+ // We differentiate between these types by the functor's return type.
73
+ //
74
+ // This is currently for analysis only, as part of an ongoing LSC investigation.
75
+ template <typename Fn, typename Arg, typename Expected>
76
+ inline constexpr bool kResultMatches =
77
+ std::is_same_v<std::decay_t<std::invoke_result_t<Fn, Arg>>, Expected>;
78
+
79
+ template <typename Adaptor, typename Builder>
80
+ using PurePolicy =
81
+ std::enable_if_t<kResultMatches<Adaptor, Builder, StatusBuilder>,
82
+ std::invoke_result_t<Adaptor, Builder>>;
83
+
84
+ template <typename Adaptor, typename Builder>
85
+ using SideEffect =
86
+ std::enable_if_t<kResultMatches<Adaptor, Builder, absl::Status>,
87
+ std::invoke_result_t<Adaptor, Builder>>;
88
+
89
+ template <typename Adaptor, typename Builder>
90
+ using Conversion =
91
+ std::enable_if_t<!kResultMatches<Adaptor, Builder, StatusBuilder> &&
92
+ !kResultMatches<Adaptor, Builder, absl::Status>,
93
+ std::invoke_result_t<Adaptor, Builder>>;
94
+
95
+ class StatusBuilderPrivateAccessor;
96
+
97
+ } // namespace status_internal
98
+
99
+ // Internal argument-dependent lookup extension point for StatusBuilder.
100
+ // Necessary for allowing StatusBuilder to be open-sourced into Abseil without
101
+ // introducing hard dependencies on non-canonical error spaces or protobuf.
102
+ //
103
+ // What we would have preferred here is to just leave
104
+ // StatusBuilder::SetErrorCode() undeclared for OSS users, but defined for
105
+ // internal users. However, C++ doesn't provide a great way to do that directly,
106
+ // since merely omitting a definition still leaves it declared and thus
107
+ // accessible.
108
+ //
109
+ // We therefore use this ADL extension point as the closest moral equivalent:
110
+ // this allows use to define a simple shell for the method in OSS, but to
111
+ // prevent its actual usage (via SFINAE) unless this extension point is also
112
+ // defined, which is only the case in our internal libraries.
113
+ void AbslInternalSetErrorCode(StatusBuilder&, absl::StatusCode);
114
+
115
+ // Specifies how to join the error message in the original status and any
116
+ // additional message that has been streamed into the builder.
117
+ enum class MessageJoinStyle {
118
+ kAnnotate,
119
+ kAppend,
120
+ kPrepend,
121
+ };
122
+
123
+ // Creates a status based on an original_status, but enriched with additional
124
+ // information. The builder implicitly converts to Status and StatusOr<T>
125
+ // allowing for it to be returned directly.
126
+ //
127
+ // StatusBuilder builder(original);
128
+ // builder.SetPayload(proto);
129
+ // builder << "info about error";
130
+ // return builder;
131
+ //
132
+ // It provides method chaining to simplify typical usage:
133
+ //
134
+ // return StatusBuilder(original)
135
+ // .Log(absl::LogSeverity::kWarning) << "oh no!";
136
+ //
137
+ // In more detail:
138
+ // - When the original status is OK, all methods become no-ops and nothing will
139
+ // be logged.
140
+ // - Messages streamed into the status builder are collected into a single
141
+ // additional message string.
142
+ // - The original Status's message and the additional message are joined
143
+ // together when the result status is built.
144
+ // - By default, the messages will be joined as if by `util::Annotate`, which
145
+ // includes a convenience separator between the original message and the
146
+ // additional one. This behavior can be changed with the `SetAppend()` and
147
+ // `SetPrepend()` methods of the builder.
148
+ // - By default, the result status is not logged. The `Log` and
149
+ // `EmitStackTrace` methods will cause the builder to log the result status
150
+ // when it is built.
151
+ // - All side effects (like logging or constructing a stack trace) happen when
152
+ // the builder is converted to a status.
153
+ class ABSL_MUST_USE_RESULT StatusBuilder {
154
+ public:
155
+ explicit StatusBuilder();
156
+ ~StatusBuilder();
157
+
158
+ // Creates a `StatusBuilder` based on an original status. If logging is
159
+ // enabled, it will use `location` as the location from which the log message
160
+ // occurs. A typical user will not specify `location`, allowing it to default
161
+ // to the current location.
162
+ explicit StatusBuilder(
163
+ const absl::Status& original_status,
164
+ absl::SourceLocation location = absl::SourceLocation::current());
165
+ explicit StatusBuilder(
166
+ absl::Status&& original_status,
167
+ absl::SourceLocation location = absl::SourceLocation::current());
168
+
169
+ // Creates a `StatusBuilder` from a status code. If logging is enabled, it
170
+ // will use `location` as the location from which the log message occurs. A
171
+ // typical user will not specify `location`, allowing it to default to the
172
+ // current location.
173
+ explicit StatusBuilder(
174
+ absl::StatusCode code,
175
+ absl::SourceLocation location = absl::SourceLocation::current());
176
+
177
+ StatusBuilder(const StatusBuilder& sb);
178
+ StatusBuilder& operator=(const StatusBuilder& sb);
179
+ StatusBuilder(StatusBuilder&&) = default;
180
+ StatusBuilder& operator=(StatusBuilder&&) = default;
181
+
182
+ // Mutates the builder so that the final additional message is prepended to
183
+ // the original error message in the status. A convenience separator is not
184
+ // placed between the messages.
185
+ //
186
+ // NOTE: Multiple calls to `SetPrepend` and `SetAppend` just adjust the
187
+ // behavior of the final join of the original status with the extra message.
188
+ //
189
+ // Returns `*this` to allow method chaining.
190
+ StatusBuilder& SetPrepend() &;
191
+ ABSL_MUST_USE_RESULT StatusBuilder&& SetPrepend() &&;
192
+
193
+ // Mutates the builder so that the final additional message is appended to the
194
+ // original error message in the status. A convenience separator is not
195
+ // placed between the messages.
196
+ //
197
+ // NOTE: Multiple calls to `SetPrepend` and `SetAppend` just adjust the
198
+ // behavior of the final join of the original status with the extra message.
199
+ //
200
+ // Returns `*this` to allow method chaining.
201
+ StatusBuilder& SetAppend() &;
202
+ ABSL_MUST_USE_RESULT StatusBuilder&& SetAppend() &&;
203
+
204
+ // Mutates the builder to disable any logging that was set using any of the
205
+ // logging functions below. Returns `*this` to allow method chaining.
206
+ StatusBuilder& SetNoLogging() &;
207
+ ABSL_MUST_USE_RESULT StatusBuilder&& SetNoLogging() &&;
208
+
209
+ // Mutates the builder so that the result status will be logged (without a
210
+ // stack trace) when this builder is converted to a Status. This overrides
211
+ // the logging settings from earlier calls to any of the logging mutator
212
+ // functions. Returns `*this` to allow method chaining.
213
+ StatusBuilder& Log(absl::LogSeverity level) &;
214
+ ABSL_MUST_USE_RESULT StatusBuilder&& Log(absl::LogSeverity level) &&;
215
+
216
+ StatusBuilder& LogError() & { return Log(absl::LogSeverity::kError); }
217
+ ABSL_MUST_USE_RESULT StatusBuilder&& LogError() && {
218
+ return std::move(LogError());
219
+ }
220
+ StatusBuilder& LogWarning() & { return Log(absl::LogSeverity::kWarning); }
221
+ ABSL_MUST_USE_RESULT StatusBuilder&& LogWarning() && {
222
+ return std::move(LogWarning());
223
+ }
224
+ StatusBuilder& LogInfo() & { return Log(absl::LogSeverity::kInfo); }
225
+ ABSL_MUST_USE_RESULT StatusBuilder&& LogInfo() && {
226
+ return std::move(LogInfo());
227
+ }
228
+
229
+ // Mutates the builder so that the result status will be logged every N
230
+ // invocations (without a stack trace) when this builder is converted to a
231
+ // Status. This overrides the logging settings from earlier calls to any of
232
+ // the logging mutator functions. Returns `*this` to allow method chaining.
233
+ StatusBuilder& LogEveryN(absl::LogSeverity level, int n) &;
234
+ ABSL_MUST_USE_RESULT StatusBuilder&& LogEveryN(absl::LogSeverity level,
235
+ int n) &&;
236
+
237
+ // Mutates the builder so that the result status will be logged once per
238
+ // period (without a stack trace) when this builder is converted to a Status.
239
+ // This overrides the logging settings from earlier calls to any of the
240
+ // logging mutator functions. Returns `*this` to allow method chaining.
241
+ // If period is absl::ZeroDuration() or less, then this is equivalent to
242
+ // calling the Log() method.
243
+ StatusBuilder& LogEvery(absl::LogSeverity level, absl::Duration period) &;
244
+ ABSL_MUST_USE_RESULT StatusBuilder&& LogEvery(absl::LogSeverity level,
245
+ absl::Duration period) &&;
246
+
247
+ // Mutates the builder so that the result status will be VLOGged (without a
248
+ // stack trace) when this builder is converted to a Status. `verbose_level`
249
+ // indicates the verbosity level that would be passed to VLOG(). This
250
+ // overrides the logging settings from earlier calls to any of the logging
251
+ // mutator functions. Returns `*this` to allow method chaining.
252
+ StatusBuilder& VLog(int verbose_level) &;
253
+ ABSL_MUST_USE_RESULT StatusBuilder&& VLog(int verbose_level) &&;
254
+
255
+ // Mutates the builder so that a stack trace will be logged if the status is
256
+ // logged. One of the logging setters above should be called as well. If
257
+ // logging is not yet enabled this behaves as if LogInfo().EmitStackTrace()
258
+ // was called. Returns `*this` to allow method chaining.
259
+ StatusBuilder& EmitStackTrace() &;
260
+ ABSL_MUST_USE_RESULT StatusBuilder&& EmitStackTrace() &&;
261
+
262
+ // Mutates the builder so that the result status will also be logged to the
263
+ // provided `sink` when this builder is converted to a status. Overwrites any
264
+ // sink set prior. The provided `sink` must point to a valid object by the
265
+ // time this builder is converted to a status. Has no effect if this builder
266
+ // is not configured to log by calling any of the LogXXX methods. Returns
267
+ // `*this` to allow method chaining.
268
+ StatusBuilder& AlsoOutputToSink(absl::LogSink* sink) &;
269
+ ABSL_MUST_USE_RESULT StatusBuilder&& AlsoOutputToSink(absl::LogSink* sink) &&;
270
+
271
+ // Mutates the builder so that the result status will only be logged to the
272
+ // provided `sink` when this builder is converted to a status. Overwrites any
273
+ // sink set prior. The provided `sink` must point to a valid object by the
274
+ // time this builder is converted to a status. Has no effect if this builder
275
+ // is not configured to log by calling any of the LogXXX methods. Returns
276
+ // `*this` to allow method chaining.
277
+ StatusBuilder& OnlyOutputToSink(absl::LogSink* sink) &;
278
+ ABSL_MUST_USE_RESULT StatusBuilder&& OnlyOutputToSink(absl::LogSink* sink) &&;
279
+
280
+ // Appends to the extra message that will be added to the original status. By
281
+ // default, the extra message is added to the original message as if by
282
+ // `util::Annotate`, which includes a convenience separator between the
283
+ // original message and the enriched one.
284
+ template <typename T>
285
+ StatusBuilder& operator<<(const T& value) &;
286
+
287
+ template <typename T>
288
+ ABSL_MUST_USE_RESULT StatusBuilder&& operator<<(const T& value) &&;
289
+
290
+ // Adds a payload for the status that will be returned by this StatusBuilder.
291
+ // Note that this is equivalent to `Status::SetPayload`, to attach protos to
292
+ // the MessageSet payload, use `util::AttachPayload`. Returns '*this' to allow
293
+ // method chaining.
294
+ StatusBuilder& SetPayload(absl::string_view type_url, absl::Cord payload) &;
295
+ ABSL_MUST_USE_RESULT StatusBuilder&& SetPayload(absl::string_view type_url,
296
+ absl::Cord payload) && {
297
+ return std::move(SetPayload(type_url, std::move(payload)));
298
+ }
299
+
300
+ std::optional<absl::Cord> GetPayload(absl::string_view type_url) const;
301
+
302
+ // INTERNAL API. NOT FOR PUBLIC USE.
303
+ template <typename MessageSetExtension, typename ExtensionIdentifier>
304
+ auto AttachPayload(const MessageSetExtension& obj,
305
+ const ExtensionIdentifier& id) & //
306
+ -> std::enable_if_t<
307
+ std::is_void_v<decltype(AbslInternalAttachPayload(*this, obj, id))>,
308
+ StatusBuilder&> {
309
+ AbslInternalAttachPayload(*this, obj, id);
310
+ return *this;
311
+ }
312
+
313
+ // As above, but &&-qualified.
314
+ //
315
+ // Uses decltype() to propagate template constraints (SFINAE).
316
+ template <typename MessageSetExtension, typename ExtensionIdentifier>
317
+ ABSL_MUST_USE_RESULT auto AttachPayload(const MessageSetExtension& obj,
318
+ const ExtensionIdentifier& id) && //
319
+ -> decltype(std::move(AttachPayload(obj, id))) {
320
+ return std::move(AttachPayload(obj, id));
321
+ }
322
+
323
+ // Like `AttachPayload() &`, but with the default extension ID.
324
+ //
325
+ // INTERNAL API. NOT FOR PUBLIC USE.
326
+ template <typename MessageSetExtension>
327
+ auto AttachPayload(const MessageSetExtension& obj) & //
328
+ -> std::enable_if_t<
329
+ std::is_void_v<decltype(AbslInternalAttachPayload(*this, obj))>,
330
+ StatusBuilder&> {
331
+ AbslInternalAttachPayload(*this, obj);
332
+ return *this;
333
+ }
334
+
335
+ // As above, but &&-qualified.
336
+ //
337
+ // Uses decltype() to propagate template constraints (SFINAE).
338
+ template <typename MessageSetExtension>
339
+ ABSL_MUST_USE_RESULT auto AttachPayload(const MessageSetExtension& obj) && //
340
+ -> decltype(std::move(AttachPayload(obj))) {
341
+ return std::move(AttachPayload(obj));
342
+ }
343
+
344
+ // HasPayload()
345
+ //
346
+ // Indicates whether the Status object that will be returned by the
347
+ // StatusBuilder contains any payloads with a type extending proto2's
348
+ // `MessageSet`, returning `true` if so. Having a payload does not guarantee
349
+ // the presence of a payload with a specific type. Note that returning `false`
350
+ // does not necessarily indicate the absence of a payload, but only the
351
+ // absence on one which extends `MessageSet`.
352
+ bool HasPayload() const;
353
+
354
+ // INTERNAL API. NOT FOR PUBLIC USE.
355
+ template <typename Enum>
356
+ auto SetErrorCode(Enum code) & //
357
+ -> std::enable_if_t<
358
+ std::is_void_v<decltype(AbslInternalSetErrorCode(*this, code))>,
359
+ StatusBuilder&> {
360
+ AbslInternalSetErrorCode(*this, code);
361
+ return *this;
362
+ }
363
+
364
+ // As above, but &&-qualified.
365
+ //
366
+ // Uses decltype() to propagate template constraints (SFINAE).
367
+ template <typename Enum>
368
+ ABSL_MUST_USE_RESULT auto SetErrorCode(Enum code) && //
369
+ -> decltype(std::move(SetErrorCode(code))) {
370
+ return std::move(SetErrorCode(code));
371
+ }
372
+
373
+ // Sets the status code for the status that will be returned by this
374
+ // StatusBuilder. Returns `*this` to allow method chaining.
375
+ StatusBuilder& SetCode(absl::StatusCode code) &;
376
+ ABSL_MUST_USE_RESULT StatusBuilder&& SetCode(absl::StatusCode code) && {
377
+ return std::move(SetCode(code));
378
+ }
379
+
380
+ ///////////////////////////////// Adaptors /////////////////////////////////
381
+ //
382
+ // A StatusBuilder `adaptor` is a functor which can be included in a builder
383
+ // method chain. There are two common variants:
384
+ //
385
+ // 1. `Pure policy` adaptors modify the StatusBuilder and return the modified
386
+ // object, which can then be chained with further adaptors or mutations.
387
+ //
388
+ // 2. `Terminal` adaptors consume the builder's Status and return some
389
+ // other type of object. Alternatively, the consumed Status may be used
390
+ // for side effects, e.g. by passing it to a side channel. A terminal
391
+ // adaptor cannot be chained.
392
+ //
393
+ // Careful: The conversion of StatusBuilder to Status has side effects!
394
+ // Adaptors must ensure that this conversion happens at most once in the
395
+ // builder chain. The easiest way to do this is to determine the adaptor type
396
+ // and follow the corresponding guidelines:
397
+ //
398
+ // Pure policy adaptors should:
399
+ // (a) Take a StatusBuilder as input parameter.
400
+ // (b) NEVER convert the StatusBuilder to Status:
401
+ // - Never assign the builder to a Status variable.
402
+ // - Never pass the builder to a function whose parameter type is Status,
403
+ // including by reference (e.g. const Status&).
404
+ // - Never pass the builder to any function which might convert the
405
+ // builder to Status (i.e. this restriction is viral).
406
+ // (c) Return a StatusBuilder (usually the input parameter).
407
+ //
408
+ // Terminal adaptors should:
409
+ // (a) Take a Status as input parameter (not a StatusBuilder!).
410
+ // (b) Return a type matching the enclosing function. (This can be `void`.)
411
+ //
412
+ // Adaptors do not necessarily fit into one of these categories. However, any
413
+ // which satisfies the conversion rule can always be decomposed into a pure
414
+ // adaptor chained into a terminal adaptor. (This is recommended.)
415
+ //
416
+ // Examples
417
+ //
418
+ // Pure adaptors allow teams to configure team-specific error handling
419
+ // policies. For example:
420
+ //
421
+ // StatusBuilder TeamPolicy(StatusBuilder builder) {
422
+ // builder.SetPayload(...);
423
+ // return std::move(builder).Log(absl::LogSeverity::kWarning);
424
+ // }
425
+ //
426
+ // ABSL_RETURN_IF_ERROR(foo()).With(TeamPolicy);
427
+ //
428
+ // Because pure policy adaptors return the modified StatusBuilder, they
429
+ // can be chained with further adaptors, e.g.:
430
+ //
431
+ // ABSL_RETURN_IF_ERROR(foo()).With(TeamPolicy).With(OtherTeamPolicy);
432
+ //
433
+ // Terminal adaptors are often used for type conversion. This allows
434
+ // ABSL_RETURN_IF_ERROR to be used in functions which do not return Status.
435
+ // For example, a function might want to return some default value on error:
436
+ //
437
+ // int GetSysCounter() {
438
+ // int value;
439
+ // ABSL_RETURN_IF_ERROR(ReadCounterFile(filename, &value))
440
+ // .LogInfo()
441
+ // .With([](const absl::Status& unused) { return 0; });
442
+ // return value;
443
+ // }
444
+ //
445
+ // For the simple case of returning a constant (e.g. zero, false, nullptr) on
446
+ // error, consider `status_macros::Return` or `status_macros::ReturnVoid`:
447
+ //
448
+ // #include "util/task/contrib/status_macros/return.h"
449
+ //
450
+ // bool DoMyThing() {
451
+ // ABSL_RETURN_IF_ERROR(foo()).LogWarning().With(status_macros::Return(false));
452
+ // ...
453
+ // }
454
+ //
455
+ // A terminal adaptor may instead (or additionally) be used to create side
456
+ // effects that are not supported natively by `StatusBuilder`, such as
457
+ // returning the Status through a side channel. For example,
458
+ // `util::TaskReturn` returns the Status through the `util::Task` that it was
459
+ // initialized with. This adaptor then returns `void`, to match the typical
460
+ // return type of functions that maintain state through `util::Task`:
461
+ //
462
+ // class TaskReturn {
463
+ // public:
464
+ // explicit TaskReturn(Task* t) : task_(t) {}
465
+ // void operator()(const Status& status) const { task_->Return(status); }
466
+ // // ...
467
+ // };
468
+ //
469
+ // void Read(absl::string_view name, util::Task* task) {
470
+ // int64 id;
471
+ // ABSL_RETURN_IF_ERROR(GetIdForName(name, &id)).With(TaskReturn(task));
472
+ // ABSL_RETURN_IF_ERROR(ReadForId(id)).With(TaskReturn(task));
473
+ // task->Return();
474
+ // }
475
+
476
+ // Calls `adaptor` on this status builder to apply policies, type conversions,
477
+ // and/or side effects on the StatusBuilder. Returns the value returned by
478
+ // `adaptor`, which may be any type including `void`. See comments above.
479
+ //
480
+ // Style guide exception for Ref qualified methods and rvalue refs
481
+ // (cl/128258530). This allows us to avoid a copy in the common case.
482
+ //
483
+ // Note: All With() overrides are equivalent, and return Adaptor(this). They
484
+ // are part of an ongoing LSC investigation.
485
+ template <typename Adaptor>
486
+ auto With(Adaptor&& adaptor) & -> status_internal::PurePolicy<
487
+ Adaptor, StatusBuilder&> {
488
+ return std::forward<Adaptor>(adaptor)(*this);
489
+ }
490
+ template <typename Adaptor>
491
+ ABSL_MUST_USE_RESULT auto With(
492
+ Adaptor&&
493
+ adaptor) && -> status_internal::PurePolicy<Adaptor, StatusBuilder&&> {
494
+ return std::forward<Adaptor>(adaptor)(std::move(*this));
495
+ }
496
+
497
+ template <typename Adaptor>
498
+ auto With(Adaptor&& adaptor) & -> status_internal::SideEffect<
499
+ Adaptor, StatusBuilder&> {
500
+ return std::forward<Adaptor>(adaptor)(*this);
501
+ }
502
+ template <typename Adaptor>
503
+ ABSL_MUST_USE_RESULT auto With(
504
+ Adaptor&&
505
+ adaptor) && -> status_internal::SideEffect<Adaptor, StatusBuilder&&> {
506
+ return std::forward<Adaptor>(adaptor)(std::move(*this));
507
+ }
508
+
509
+ template <typename Adaptor>
510
+ auto With(Adaptor&& adaptor) & -> status_internal::Conversion<
511
+ Adaptor, StatusBuilder&> {
512
+ return std::forward<Adaptor>(adaptor)(*this);
513
+ }
514
+ template <typename Adaptor>
515
+ ABSL_MUST_USE_RESULT auto With(
516
+ Adaptor&&
517
+ adaptor) && -> status_internal::Conversion<Adaptor, StatusBuilder&&> {
518
+ return std::forward<Adaptor>(adaptor)(std::move(*this));
519
+ }
520
+
521
+ // Returns true if the Status created by this builder will be ok().
522
+ ABSL_MUST_USE_RESULT bool ok() const;
523
+
524
+ // Returns the (canonical) error code for the Status created by this builder.
525
+ absl::StatusCode code() const;
526
+
527
+ // Implicit conversion to Status.
528
+ //
529
+ // Careful: this operator has side effects, so it should be called at
530
+ // most once. In particular, do NOT use this conversion operator to inspect
531
+ // the status from an adapter object passed into With().
532
+ //
533
+ // Style guide exception for using Ref qualified methods and for implicit
534
+ // conversions (cl/124566728). This override allows us to implement
535
+ // ABSL_RETURN_IF_ERROR with 2 move operations in the common case.
536
+ operator absl::Status() const&; // NOLINT: Builder converts implicitly.
537
+ operator absl::Status() &&; // NOLINT: Builder converts implicitly.
538
+
539
+ // Returns the source location used to create this builder. This differs from
540
+ // `GetPreviousSourceLocations()` as this location is the single location for
541
+ // the creation of this builder.
542
+ ABSL_MUST_USE_RESULT absl::SourceLocation source_location() const;
543
+
544
+ // Returns the source locations previously recorded in the status. This will
545
+ // not include the source location of the `StatusBuilder` itself (which is
546
+ // available via `source_location()`). When the builder is converted to a
547
+ // Status, the builder's location will be appended to this list of previous
548
+ // locations. For `StatusBuilder`s created without an original status (e.g.,
549
+ // from a status code), this will be empty.
550
+ decltype(auto) GetPreviousSourceLocations() const {
551
+ if (rep_ == nullptr) {
552
+ return absl::OkStatus().GetSourceLocations();
553
+ }
554
+ return rep_->status.GetSourceLocations();
555
+ }
556
+
557
+ // Returns a string based on the `mode`. This produces the same string as
558
+ // would converting to a Status and calling operator<<, but it does so without
559
+ // side effects (e.g., logging). Therefore, it is safe to use from within an
560
+ // adapter object passed into With().
561
+ std::string ToString() const;
562
+
563
+ private:
564
+ friend class status_internal::StatusBuilderPrivateAccessor;
565
+
566
+ // Returns true if the compiler can determine that the instance is empty. That
567
+ // is, `rep_ == nullptr`.
568
+ // A `false` return does not necessarily indicate that it has a rep. It just
569
+ // can't prove it doesn't.
570
+ ABSL_ATTRIBUTE_ALWAYS_INLINE bool IsKnownToBeEmpty() const {
571
+ #if ABSL_HAVE_BUILTIN(__builtin_constant_p)
572
+ // __builtin_constant_p does not like it when it has non trivial expressions
573
+ // in it, and `rep_==nullptr` is a user-defined operator.
574
+ // Do it out of the builtin and pass the bool instead.
575
+ bool is_empty = rep_ == nullptr;
576
+ return __builtin_constant_p(is_empty) && is_empty;
577
+ #else
578
+ return false;
579
+ #endif
580
+ }
581
+
582
+ // Tells the compiler that it can assume that `rep_` is null.
583
+ // This is verified in non-opt mode.
584
+ void AssumeEmpty() const {
585
+ if (rep_ != nullptr) ABSL_UNREACHABLE();
586
+ }
587
+
588
+ static std::string CurrentStackTrace();
589
+
590
+ struct Rep;
591
+ // Destroy the `Rep` object. It is just calling the destructor of the
592
+ // `unique_ptr`, but out of line.
593
+ static void Destroy(std::unique_ptr<Rep>);
594
+
595
+ // Creates a Status from this builder and logs it if the builder has been
596
+ // configured to log itself.
597
+ // NOTE: This function is `static` to prevent escaping the `this` pointer. We
598
+ // transfer the `Rep` to delegate the destruction.
599
+ static absl::Status CreateStatusAndConditionallyLog(absl::SourceLocation loc,
600
+ std::unique_ptr<Rep> rep);
601
+
602
+ // Infrequently set builder options, instantiated lazily. This reduces
603
+ // average construction/destruction time (e.g. the `stream` is fairly
604
+ // expensive). Stacks can also be blown if StatusBuilder grows too large.
605
+ // This is primarily an issue for debug builds, which do not necessarily
606
+ // re-use stack space within a function across the sub-scopes used by
607
+ // status macros.
608
+ struct Rep {
609
+ explicit Rep(const absl::Status& s);
610
+ explicit Rep(absl::Status&& s);
611
+ Rep(const Rep& r);
612
+ ~Rep();
613
+ void InitStream();
614
+
615
+ // The status that the result will be based on. Can be modified by
616
+ // SetPayload().
617
+ absl::Status status;
618
+
619
+ enum class LoggingMode {
620
+ kDisabled,
621
+ kLog,
622
+ kVLog,
623
+ kLogEveryN,
624
+ kLogEveryPeriod
625
+ };
626
+ LoggingMode logging_mode = LoggingMode::kDisabled;
627
+
628
+ // The severity level at which the Status should be logged. Note that
629
+ // `logging_mode == LoggingMode::kVLog` always logs at severity INFO.
630
+ absl::LogSeverity log_severity;
631
+
632
+ // The level at which the Status should be VLOGged.
633
+ // Only used when `logging_mode == LoggingMode::kVLog`.
634
+ int verbose_level;
635
+
636
+ // Only log every N invocations.
637
+ // Only used when `logging_mode == LoggingMode::kLogEveryN`.
638
+ int n;
639
+
640
+ // Only log once per period.
641
+ // Only used when `logging_mode == LoggingMode::kLogEveryPeriod`.
642
+ absl::Duration period;
643
+
644
+ // Gathers additional messages added with `<<` for use in the final status.
645
+ std::string stream_message;
646
+ std::optional<status_internal::Stream> stream;
647
+
648
+ // If not nullptr, specifies the log sink where log output should be
649
+ // sent to. Only used when `logging_mode != LoggingMode::kDisabled`.
650
+ absl::LogSink* sink = nullptr;
651
+
652
+ // Specifies how to join the message in `status` and `stream`.
653
+ MessageJoinStyle message_join_style = MessageJoinStyle::kAnnotate;
654
+
655
+ // Whether to log stack trace. Only used when `logging_mode !=
656
+ // LoggingMode::kDisabled`.
657
+ bool should_log_stack_trace = false;
658
+
659
+ // When this is true, will send both to `sink` and will log. When this is
660
+ // false, will only send to `sink`.
661
+ bool also_send_to_log = true;
662
+ };
663
+
664
+ static Rep* InitRep(const absl::Status& s) {
665
+ if (s.ok()) {
666
+ return nullptr;
667
+ } else {
668
+ return new Rep(s);
669
+ }
670
+ }
671
+
672
+ static Rep* InitRep(absl::Status&& s) {
673
+ if (s.ok()) {
674
+ return nullptr;
675
+ } else {
676
+ Rep* rep = InitRepImpl(std::move(s));
677
+ ABSL_ASSUME(rep != nullptr);
678
+ return rep;
679
+ }
680
+ }
681
+
682
+ // Out of line function that constructs the Rep.
683
+ // Note that `s` is by value because of the TRIVIAL_ABI.
684
+ static Rep* InitRepImpl(absl::Status s);
685
+
686
+ // The location to record if this status is logged.
687
+ absl::SourceLocation loc_;
688
+
689
+ // nullptr if the result status will be OK. Extra fields moved to the heap to
690
+ // minimize stack space.
691
+ std::unique_ptr<Rep> rep_;
692
+
693
+ // For testing Rep's implememntation.
694
+ friend class StatusBuilderTest;
695
+ };
696
+
697
+ // Implicitly converts `builder` to `Status` and write it to `os`.
698
+ std::ostream& operator<<(std::ostream& os, const StatusBuilder& builder);
699
+ std::ostream& operator<<(std::ostream& os, StatusBuilder&& builder);
700
+
701
+ // StatusBuilder policy to append an extra message to the original status.
702
+ //
703
+ // This is most useful with adaptors such as util::TaskReturn that otherwise
704
+ // would prevent use of operator<<. For example:
705
+ //
706
+ // ABSL_RETURN_IF_ERROR(foo(val))
707
+ // .With(util::ExtraMessage("when calling foo()"))
708
+ // .With(util::TaskReturn(task));
709
+ //
710
+ // or
711
+ //
712
+ // ABSL_RETURN_IF_ERROR(foo(val))
713
+ // .With(util::ExtraMessage() << "val: " << val)
714
+ // .With(util::TaskReturn(task));
715
+ //
716
+ // Note in the above example, the ABSL_RETURN_IF_ERROR macro ensures the
717
+ // ExtraMessage expression is evaluated only in the error case, so efficiency of
718
+ // constructing the message is not a concern in the success case.
719
+ class ExtraMessage {
720
+ public:
721
+ ExtraMessage() : ExtraMessage(std::string()) {}
722
+ explicit ExtraMessage(std::string msg)
723
+ : msg_(std::move(msg)), stream_(msg_) {}
724
+
725
+ ExtraMessage(
726
+ ExtraMessage&& other) noexcept // strings::OStringStream is stateless
727
+ // so we can simply move over the message.
728
+ : ExtraMessage(std::move(other.msg_)) {}
729
+
730
+ // Appends to the extra message that will be added to the original status. By
731
+ // default, the extra message is added to the original message as if by
732
+ // `util::Annotate`, which includes a convenience separator between the
733
+ // original message and the enriched one.
734
+ template <typename T>
735
+ ExtraMessage& operator<<(const T& value) & {
736
+ stream_ << value;
737
+ return *this;
738
+ }
739
+
740
+ // As above, preserving the rvalue-ness of the ExtraMessage object.
741
+ template <typename T>
742
+ ExtraMessage&& operator<<(const T& value) && {
743
+ *this << value;
744
+ return std::move(*this);
745
+ }
746
+
747
+ // Appends to the extra message that will be added to the original status. By
748
+ // default, the extra message is added to the original message as if by
749
+ // `util::Annotate`, which includes a convenience separator between the
750
+ // original message and the enriched one.
751
+ StatusBuilder operator()(StatusBuilder builder) const {
752
+ builder << msg_;
753
+ return builder;
754
+ }
755
+
756
+ private:
757
+ std::string msg_;
758
+ status_internal::Stream stream_;
759
+ };
760
+
761
+ // Implementation details follow; clients should ignore.
762
+
763
+ inline StatusBuilder::StatusBuilder(absl::StatusCode code,
764
+ absl::SourceLocation location)
765
+ : loc_(location), rep_(InitRep(absl::Status(code, ""))) {}
766
+
767
+ inline StatusBuilder::StatusBuilder(const StatusBuilder& sb) : loc_(sb.loc_) {
768
+ if (sb.rep_ != nullptr) {
769
+ rep_ = std::make_unique<Rep>(*sb.rep_);
770
+ }
771
+ }
772
+
773
+ inline StatusBuilder::StatusBuilder(absl::Status&& original_status,
774
+ absl::SourceLocation location)
775
+ : loc_(location), rep_(InitRep(std::move(original_status))) {}
776
+
777
+ inline StatusBuilder::~StatusBuilder() {
778
+ if (IsKnownToBeEmpty()) {
779
+ // Nothing to do.
780
+ return;
781
+ }
782
+ // We will run the destructor logic, so move it out of line.
783
+ // The destructor of the unique_ptr runs ~Rep() and then ::operator delete.
784
+ // We don't want that bloat on the caller.
785
+ Destroy(std::move(rep_));
786
+ // Tell the compiler that `rep_` was not filled again even if `this` escaped.
787
+ AssumeEmpty();
788
+ }
789
+
790
+ inline StatusBuilder& StatusBuilder::operator=(const StatusBuilder& sb) {
791
+ loc_ = sb.loc_;
792
+ if (sb.rep_ != nullptr) {
793
+ rep_ = std::make_unique<Rep>(*sb.rep_);
794
+ } else {
795
+ rep_ = nullptr;
796
+ }
797
+ return *this;
798
+ }
799
+
800
+ inline StatusBuilder& StatusBuilder::SetPrepend() & {
801
+ if (rep_ == nullptr) return *this;
802
+ rep_->message_join_style = MessageJoinStyle::kPrepend;
803
+ return *this;
804
+ }
805
+ inline StatusBuilder&& StatusBuilder::SetPrepend() && {
806
+ return std::move(SetPrepend());
807
+ }
808
+
809
+ inline StatusBuilder& StatusBuilder::SetAppend() & {
810
+ if (rep_ == nullptr) return *this;
811
+ rep_->message_join_style = MessageJoinStyle::kAppend;
812
+ return *this;
813
+ }
814
+ inline StatusBuilder&& StatusBuilder::SetAppend() && {
815
+ return std::move(SetAppend());
816
+ }
817
+
818
+ inline StatusBuilder& StatusBuilder::SetNoLogging() & {
819
+ if (rep_ != nullptr) {
820
+ rep_->logging_mode = Rep::LoggingMode::kDisabled;
821
+ rep_->should_log_stack_trace = false;
822
+ }
823
+ return *this;
824
+ }
825
+ inline StatusBuilder&& StatusBuilder::SetNoLogging() && {
826
+ return std::move(SetNoLogging());
827
+ }
828
+
829
+ inline StatusBuilder& StatusBuilder::Log(absl::LogSeverity level) & {
830
+ if (rep_ == nullptr) return *this;
831
+ rep_->logging_mode = Rep::LoggingMode::kLog;
832
+ rep_->log_severity = level;
833
+ return *this;
834
+ }
835
+ inline StatusBuilder&& StatusBuilder::Log(absl::LogSeverity level) && {
836
+ return std::move(Log(level));
837
+ }
838
+
839
+ inline StatusBuilder& StatusBuilder::LogEveryN(absl::LogSeverity level,
840
+ int n) & {
841
+ if (rep_ == nullptr) return *this;
842
+ if (n < 1) return Log(level);
843
+ rep_->logging_mode = Rep::LoggingMode::kLogEveryN;
844
+ rep_->log_severity = level;
845
+ rep_->n = n;
846
+ return *this;
847
+ }
848
+ inline StatusBuilder&& StatusBuilder::LogEveryN(absl::LogSeverity level,
849
+ int n) && {
850
+ return std::move(LogEveryN(level, n));
851
+ }
852
+
853
+ inline StatusBuilder& StatusBuilder::LogEvery(absl::LogSeverity level,
854
+ absl::Duration period) & {
855
+ if (rep_ == nullptr) return *this;
856
+ if (period <= absl::ZeroDuration()) return Log(level);
857
+ rep_->logging_mode = Rep::LoggingMode::kLogEveryPeriod;
858
+ rep_->log_severity = level;
859
+ rep_->period = period;
860
+ return *this;
861
+ }
862
+ inline StatusBuilder&& StatusBuilder::LogEvery(absl::LogSeverity level,
863
+ absl::Duration period) && {
864
+ return std::move(LogEvery(level, period));
865
+ }
866
+
867
+ inline StatusBuilder& StatusBuilder::VLog(int verbose_level) & {
868
+ if (rep_ == nullptr) return *this;
869
+ rep_->logging_mode = Rep::LoggingMode::kVLog;
870
+ rep_->verbose_level = verbose_level;
871
+ return *this;
872
+ }
873
+ inline StatusBuilder&& StatusBuilder::VLog(int verbose_level) && {
874
+ return std::move(VLog(verbose_level));
875
+ }
876
+
877
+ inline StatusBuilder& StatusBuilder::EmitStackTrace() & {
878
+ if (rep_ == nullptr) return *this;
879
+ if (rep_->logging_mode == Rep::LoggingMode::kDisabled) {
880
+ // Default to INFO logging, otherwise nothing would be emitted.
881
+ rep_->logging_mode = Rep::LoggingMode::kLog;
882
+ rep_->log_severity = absl::LogSeverity::kInfo;
883
+ }
884
+ rep_->should_log_stack_trace = true;
885
+ return *this;
886
+ }
887
+ inline StatusBuilder&& StatusBuilder::EmitStackTrace() && {
888
+ return std::move(EmitStackTrace());
889
+ }
890
+
891
+ inline StatusBuilder& StatusBuilder::AlsoOutputToSink(absl::LogSink* sink) & {
892
+ if (rep_ == nullptr) return *this;
893
+ rep_->sink = sink;
894
+ rep_->also_send_to_log = true;
895
+ return *this;
896
+ }
897
+ inline StatusBuilder&& StatusBuilder::AlsoOutputToSink(absl::LogSink* sink) && {
898
+ return std::move(AlsoOutputToSink(sink));
899
+ }
900
+ inline StatusBuilder& StatusBuilder::OnlyOutputToSink(absl::LogSink* sink) & {
901
+ if (rep_ == nullptr) return *this;
902
+ rep_->sink = sink;
903
+ rep_->also_send_to_log = false;
904
+ return *this;
905
+ }
906
+ inline StatusBuilder&& StatusBuilder::OnlyOutputToSink(absl::LogSink* sink) && {
907
+ return std::move(OnlyOutputToSink(sink));
908
+ }
909
+
910
+ template <typename T>
911
+ StatusBuilder& StatusBuilder::operator<<(const T& value) & {
912
+ if (rep_ == nullptr) return *this;
913
+ if (!rep_->stream.has_value()) {
914
+ rep_->InitStream();
915
+ }
916
+ *rep_->stream << value;
917
+ return *this;
918
+ }
919
+
920
+ template <typename T>
921
+ StatusBuilder&& StatusBuilder::operator<<(const T& value) && {
922
+ return std::move(operator<<(value));
923
+ }
924
+
925
+ inline StatusBuilder& StatusBuilder::SetPayload(absl::string_view type_url,
926
+ absl::Cord payload) & {
927
+ if (rep_ != nullptr) {
928
+ rep_->status.SetPayload(type_url, std::move(payload));
929
+ }
930
+ return *this;
931
+ }
932
+
933
+ inline std::optional<absl::Cord> StatusBuilder::GetPayload(
934
+ absl::string_view type_url) const {
935
+ return rep_ == nullptr ? std::nullopt : rep_->status.GetPayload(type_url);
936
+ }
937
+
938
+ inline bool StatusBuilder::ok() const {
939
+ return rep_ == nullptr ? true : rep_->status.ok();
940
+ }
941
+
942
+ inline absl::StatusCode StatusBuilder::code() const {
943
+ return rep_ == nullptr ? absl::StatusCode::kOk : rep_->status.code();
944
+ }
945
+
946
+ inline StatusBuilder::operator absl::Status() && {
947
+ // Tell the compiler that the `ok()` path will return an `Ok` status, but do
948
+ // it only if the compiler can determine it at compile time.
949
+ // When it can't, we delegate this check into the out of line function.
950
+ if (IsKnownToBeEmpty()) {
951
+ return absl::OkStatus();
952
+ }
953
+ absl::Status result = CreateStatusAndConditionallyLog(loc_, std::move(rep_));
954
+ // Tell the compiler that `rep_` was not filled again even if `this` escaped.
955
+ AssumeEmpty();
956
+ return result;
957
+ }
958
+
959
+ inline absl::SourceLocation StatusBuilder::source_location() const {
960
+ return loc_;
961
+ }
962
+
963
+ // HasPayload()
964
+ //
965
+ // Indicates whether the Status object that will be returned by the
966
+ // StatusBuilder contains any payloads with a type extending proto2's
967
+ // `MessageSet`, returning `true` if so. Having a payload does not guarantee the
968
+ // presence of a payload with a specific type. Note that returning `false` does
969
+ // not necessarily indicate the absence of a payload, but only the absence on
970
+ // one which extends `MessageSet`.
971
+ inline bool HasPayload(const StatusBuilder& builder) {
972
+ return builder.HasPayload();
973
+ }
974
+
975
+ ABSL_NAMESPACE_END
976
+ } // namespace absl
977
+
978
+ #endif // ABSL_STATUS_STATUS_BUILDER_H_