P1293R1
Revision of P1293R0
2018-11-25
Mike Spertus, Symantec
mike_spertus@symantec.com
Nathan Wilson
nwilson20@gmail.com
Target: Library Evolution, Library


ostream_joiner

Summary

This paper updates the ostream_joiner proposal to reflect experience in Library Fundamentals V2 and changes in the core language since then. Specifically, we add a deduction guide to ensure that ostream_joiner is constructed correctly from a C string literal and remove the now-redundant make_ostream_joiner.

Deduction guides

With the addition of class template argument deduction in C++17, it seems desirable to get rid of the clumsy make_ostream_joiner as we did with class templates like boyer_moore_searcher. However, as Nathan Myers has pointed out, without any deduction guide, the decision to take the delimiter by reference means thatostream_joiner j(cout, ", "); produces a compile time error as the delimiter type is deduced as char const[3]. To fix this, add the following to the end of the class definition for ostream_joiner

Wording

Wording is relative to Library Fundamentals v2. In iterator.synopsis, remove the following
 template <class DelimT, class charT = char, class traits = char_traits<charT> >
      class ostream_joiner;
  template <class charT, class traits, class DelimT>
    ostream_joiner<decay_t&t;DelimT>, charT, traits>
    make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
At the end of the definition of class ostream_joiner in iterator.ostream.joiner, add the following.
};

template<class DelimT, class CharT, class Traits>
ostream_joiner(basic_ostream<CharT, Traits>, DelimT) -> ostream_joiner<DelimT, CharT, Traits>;
Remove the iterator.ostream.joiner.creation section
ostream_joiner creation function [iterator.ostream.joiner.creation]
template <class charT, class traits, class DelimT>
ostream_joiner<decay_t<DelimT>, charT, traits>
make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);

Returns:
    ostream_joiner<decay_t<DelimT>, charT, traits>(os, forward<DelimT>(delimiter));