[libcxx-commits] [PATCH] D110497: [libc++][format][3/6] Adds a __container_buffer.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 31 09:09:07 PDT 2021


Quuxplusone added a comment.

> Character by character output doesn't seem efficient

Right, IIUC, this would end up rebased on top of D112361 <https://reviews.llvm.org/D112361> or the like.



================
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:
> 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/ )


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