[libcxx-commits] [PATCH] D110497: [libc++][format][3/6] Adds a __container_buffer.
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Nov 2 10:57:17 PDT 2021
Mordante added a comment.
In D110497#3098973 <https://reviews.llvm.org/D110497#3098973>, @vitaut wrote:
> Character-by-character output, especially type erased one introduced in D110494 <https://reviews.llvm.org/D110494> doesn't seem efficient. As commented on the the previous diff the buffer and corresponding output iterator should provide access to a contiguous buffer and type erase the reallocation, not character output.
Yes I first want to get a good solution in D112361 <https://reviews.llvm.org/D112361> and then update this patch with these changes.
================
Comment at: libcxx/include/__format/buffer.h:94
+///
+/// \note a \a _Container needs to opt-in to the concept by adding a typedef
+/// \ref __enable_format_insertable with the same type as \a _Container.
----------------
vitaut wrote:
> Quuxplusone wrote:
> > vitaut wrote:
> > > opt-in to -> "opt in to" or "opt into"
> > >>! In D110497#3098970, @vitaut wrote:
> > >> Since there's no guarantee every container's insert behaves properly
> > >
> > > What does behaving properly mean? Could you give an example of a container's insert that doesn't behave properly?
> >
> > User-defined containers can make their `insert` do arbitrary things, e.g.
> > ```
> > struct Evil : std::string {
> > void insert(std::string::iterator, char *, char *) { /*no-op*/ }
> > };
> > Evil e;
> > auto evil_it = std::back_inserter(e); // uses e.push_back, which is fine
> > ```
> > (Serendipitously, Charlie Barto, of the MSVC STL, also mentioned the need to guard against this possibility in his CppCon talk "Why does std::format do that?" on Thursday. https://cppcon.digital-medium.co.uk/thursday-recordings/ )
> Makes sense, thanks for clarifying.
> >>! In D110497#3098970, @vitaut wrote:
> >> Since there's no guarantee every container's insert behaves properly
> >
> > What does behaving properly mean? Could you give an example of a container's insert that doesn't behave properly?
>
> User-defined containers can make their `insert` do arbitrary things, e.g.
> ```
> struct Evil : std::string {
> void insert(std::string::iterator, char *, char *) { /*no-op*/ }
> };
> Evil e;
> auto evil_it = std::back_inserter(e); // uses e.push_back, which is fine
> ```
> (Serendipitously, Charlie Barto, of the MSVC STL, also mentioned the need to guard against this possibility in his CppCon talk "Why does std::format do that?" on Thursday. https://cppcon.digital-medium.co.uk/thursday-recordings/ )
Yes that's the reason, interesting to see Charlie did the same. I'm looking forward to watching this talk.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110497/new/
https://reviews.llvm.org/D110497
More information about the libcxx-commits
mailing list