[PATCH] D78795: [Support] Add raw_ostream_iterator: ostream_iterator for raw_ostream.

Nicolas Guillemot via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 23:25:40 PDT 2020


nlguillemot created this revision.
nlguillemot added reviewers: bogner, qcolombet, fhahn.

Adds a class `raw_ostream_iterator` that behaves like
std::ostream_iterator, but can be used with raw_ostream.
This is useful for using raw_ostream with std algorithms.

For example, it can be used to output std containers as follows:

std::vector<double> V = { 0.1, 0.2, 0.3 };
std::copy(V.begin(), V.end(), raw_ostream_iterator<double>(outs(), ", "));
// Output: "0.1, 0.2, 0.3, "

The API tries to follow std::ostream_iterator as closely as is
practically possible.


https://reviews.llvm.org/D78795

Files:
  llvm/include/llvm/Support/raw_ostream.h
  llvm/unittests/Support/raw_ostream_test.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78795.259812.patch
Type: text/x-patch
Size: 3763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200424/538a9158/attachment-0001.bin>


More information about the llvm-commits mailing list