Page MenuHomePhabricator

Implement LWG#1203 for raw_ostream
ClosedPublic

Authored by csigg on Nov 25 2019, 10:56 AM.

Details

Summary

Implement LWG#1203 (https://cplusplus.github.io/LWG/issue1203) for raw_ostream like libc++ does for std::basic_ostream<...>.

Add a operator<< overload that takes an rvalue reference of a typed derived from raw_ostream, streams the value to it and returns the stream of the same type as the argument.

This allows free operator<< to work with rvalue reference raw_ostreams:
raw_ostream& operator<<(raw_ostream&, const SomeType& Value);
raw_os_ostream(std::cout) << SomeType();

It also allows using the derived type like:
auto Foo = (raw_string_ostream(buffer) << "foo").str();

Diff Detail

Event Timeline

csigg created this revision.Nov 25 2019, 10:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2019, 10:56 AM
timshen accepted this revision.Nov 27 2019, 2:24 PM
timshen added a reviewer: timshen.
timshen added inline comments.
llvm/include/llvm/Support/raw_ostream.h
361

std::is_lvalue_reference -> std::is_reference? The semantics is the same (since OStream can never by an rvalue reference), but the spelling is shorter.

This revision is now accepted and ready to land.Nov 27 2019, 2:25 PM
csigg updated this revision to Diff 231367.Nov 28 2019, 1:30 AM

Changed is_lvalue_reference to is_reference

csigg added a comment.Nov 29 2019, 6:07 AM

Could someone please merge the latest revision?

(I'm not impatient. The phabricator docs suggests that I ask for this. This is my first PR to LLVM, let me know if I'm off.)

This revision was automatically updated to reflect the committed changes.