[all-commits] [llvm/llvm-project] 7479a2: [Support] Add raw_ostream_iterator: ostream_iterat...

Nicolas Guillemot via All-commits all-commits at lists.llvm.org
Thu Mar 4 11:13:22 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7479a2e00bc41f399942e5106fbdf9b4b0c11506
      https://github.com/llvm/llvm-project/commit/7479a2e00bc41f399942e5106fbdf9b4b0c11506
  Author: Nicolas Guillemot <nguillemot at apple.com>
  Date:   2021-03-04 (Thu, 04 Mar 2021)

  Changed paths:
    M llvm/include/llvm/Support/raw_ostream.h
    M llvm/unittests/Support/raw_ostream_test.cpp

  Log Message:
  -----------
  [Support] Add raw_ostream_iterator: ostream_iterator for raw_ostream

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<int> V = { 1, 2, 3 };
std::copy(V.begin(), V.end(), raw_ostream_iterator<int>(outs(), ", "));
// Output: "1, 2, 3, "
```

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

Reviewed By: dblaikie, mkitzan

Differential Revision: https://reviews.llvm.org/D78795




More information about the All-commits mailing list