diff options
author | Tsige Solomon <tsige@google.com> | 2023-06-21 08:52:53 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-21 08:53:52 -0700 |
commit | 34eb767645347f100bdd66fc1e35eee96e357961 (patch) | |
tree | 5257457b09e5c1533b41e9607fdefd20ef158eae /absl/numeric/int128.h | |
parent | 166d71d18f01aa73fd35aae611692320952a75b5 (diff) | |
download | abseil-34eb767645347f100bdd66fc1e35eee96e357961.tar.gz abseil-34eb767645347f100bdd66fc1e35eee96e357961.tar.bz2 abseil-34eb767645347f100bdd66fc1e35eee96e357961.zip |
Support for int128 to string type conversion.
PiperOrigin-RevId: 542269673
Change-Id: Ib6f7e9a57f83d73dd6fb9c45fc9f85ff0fdd75fe
Diffstat (limited to 'absl/numeric/int128.h')
-rw-r--r-- | absl/numeric/int128.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/absl/numeric/int128.h b/absl/numeric/int128.h index aa0f86f7..7530a793 100644 --- a/absl/numeric/int128.h +++ b/absl/numeric/int128.h @@ -32,6 +32,7 @@ #include <cstring> #include <iosfwd> #include <limits> +#include <string> #include <utility> #include "absl/base/config.h" @@ -217,9 +218,17 @@ class return H::combine(std::move(h), Uint128High64(v), Uint128Low64(v)); } + // Support for absl::StrCat() etc. + template <typename Sink> + friend void AbslStringify(Sink& sink, uint128 v) { + sink.Append(v.ToString()); + } + private: constexpr uint128(uint64_t high, uint64_t low); + std::string ToString() const; + // TODO(strel) Update implementation to use __int128 once all users of // uint128 are fixed to not depend on alignof(uint128) == 8. Also add // alignas(16) to class definition to keep alignment consistent across @@ -454,9 +463,17 @@ class int128 { return H::combine(std::move(h), Int128High64(v), Int128Low64(v)); } + // Support for absl::StrCat() etc. + template <typename Sink> + friend void AbslStringify(Sink& sink, int128 v) { + sink.Append(v.ToString()); + } + private: constexpr int128(int64_t high, uint64_t low); + std::string ToString() const; + #if defined(ABSL_HAVE_INTRINSIC_INT128) __int128 v_; #else // ABSL_HAVE_INTRINSIC_INT128 |