Introduce StringBuilder utility around raw_string_ostream

Chandler Carruth chandlerc at
Thu Jun 12 04:33:12 PDT 2014

On Thu, Jun 12, 2014 at 5:25 AM, Alp Toker <alp at> wrote:

> Replaces the pattern:
>   std::string buf;
>   raw_string_ostream os(buf);
>   ...
>   os.flush();
>   use(buf);

So this pattern should be:

  std::string buf;
  raw_string_ostream os(buf);

> with:
>   StringBuilder os;
>   ...
>   use (os.str());

Which is now almost identical to this. What's the advantage?

The reason I like the current form is that it makes it obvious and easy to
re-use storage where that is reasonable, and it makes variations with
SmallString more obviously the same pattern with a different storage.

We could even add a 'make_raw_ostream' or some such so that the pattern can

  Foo storage;
  auto os(make_raw_ostream(storage));

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the llvm-commits mailing list