summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/strings/cord.h8
-rw-r--r--absl/strings/cord_test.cc7
-rw-r--r--absl/strings/internal/str_format/arg.h1
3 files changed, 16 insertions, 0 deletions
diff --git a/absl/strings/cord.h b/absl/strings/cord.h
index 1d30fde8..af013df0 100644
--- a/absl/strings/cord.h
+++ b/absl/strings/cord.h
@@ -765,6 +765,14 @@ class Cord {
cord->Append(part);
}
+ // Support automatic stringification with absl::StrCat and absl::StrFormat.
+ template <typename Sink>
+ friend void AbslStringify(Sink& sink, const absl::Cord& cord) {
+ for (absl::string_view chunk : cord.Chunks()) {
+ sink.Append(chunk);
+ }
+ }
+
// Cord::SetExpectedChecksum()
//
// Stores a checksum value with this non-empty cord instance, for later
diff --git a/absl/strings/cord_test.cc b/absl/strings/cord_test.cc
index bf507094..f1a5f39c 100644
--- a/absl/strings/cord_test.cc
+++ b/absl/strings/cord_test.cc
@@ -2656,6 +2656,13 @@ TEST_P(CordTest, Format) {
EXPECT_EQ(c, "There were 0003 little pigs.And 1 bad wolf!");
}
+TEST_P(CordTest, Stringify) {
+ absl::Cord c =
+ absl::MakeFragmentedCord({"A ", "small ", "fragmented ", "Cord", "."});
+ MaybeHarden(c);
+ EXPECT_EQ(absl::StrCat(c), "A small fragmented Cord.");
+}
+
TEST_P(CordTest, Hardening) {
absl::Cord cord("hello");
MaybeHarden(cord);
diff --git a/absl/strings/internal/str_format/arg.h b/absl/strings/internal/str_format/arg.h
index 2e017549..20483aff 100644
--- a/absl/strings/internal/str_format/arg.h
+++ b/absl/strings/internal/str_format/arg.h
@@ -158,6 +158,7 @@ template <typename T>
auto FormatConvertImpl(const T& v, FormatConversionSpecImpl,
FormatSinkImpl* sink)
-> std::enable_if_t<!std::is_enum<T>::value &&
+ !std::is_same<T, absl::Cord>::value &&
std::is_void<decltype(AbslStringify(
std::declval<FormatSink&>(), v))>::value,
ArgConvertResult<FormatConversionCharSetInternal::v>> {