[libc++][format][3/6] Adds a __container_buffer.
Instead of writing every character directly into the container by using
a `back_insert_iterator` the data is buffered in an `array`. This buffer
is then inserted to the container by calling its `insert` member function.
Since there's no guarantee every container's `insert` behaves properly
containers need to opt-in to this behaviour. The appropriate standard
containers opt-in to this behaviour.
This change improves the performance of the format functions that use a
`back_insert_iterator`.
Depends on D110495
Reviewed By: ldionne, vitaut, #libc
Differential Revision: https://reviews.llvm.org/D110497
NOKEYCHECK=True
GitOrigin-RevId: 889302292bf6607a6606a771bb2bf0ce919e80bc
diff --git a/include/string b/include/string
index a005674..88b18be 100644
--- a/include/string
+++ b/include/string
@@ -525,6 +525,7 @@
#include <__assert> // all public C++ headers provide the assertion handler
#include <__config>
#include <__debug>
+#include <__format/enable_insertable.h>
#include <__ios/fpos.h>
#include <__iterator/wrap_iter.h>
#include <__utility/auto_cast.h>
@@ -4471,6 +4472,16 @@
}
} // namespace string_literals
} // namespace literals
+
+#if _LIBCPP_STD_VER > 17
+template <>
+inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true;
+#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+template <>
+inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true;
+#endif
+#endif
+
#endif
_LIBCPP_END_NAMESPACE_STD