std::experimental::ostream_joiner (3) - Linux Manuals

std::experimental::ostream_joiner: std::experimental::ostream_joiner

NAME

std::experimental::ostream_joiner - std::experimental::ostream_joiner

Synopsis


Defined in header <experimental/iterator>
template< class DelimT,
class CharT = char, (library fundamentals TS v2)
class Traits = std::char_traits<CharT>>
class ostream_joiner;


std::experimental::ostream_joiner is a single-pass LegacyOutputIterator that writes successive objects into the std::basic_ostream object for which it was constructed, using operator<<, separated by a delimiter. The delimiter is written to the output stream between every two objects that are written. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the ostream_joiner is a no-op.
In a typical implementation, the only data members of ostream_joiner are a pointer to the associated std::basic_ostream, the delimiter, and a bool member that indicates whether the next write is for the first element in the sequence.
Compared to std::ostream_iterator, ostream_joiner prints the delimiter sequence one fewer time, and is not templated on the type of the object to be printed.

Member types


Member type Definition
char_type CharT
traits_type Traits
ostream_type std::basic_ostream<CharT, Traits>
value_type void
difference_type void
pointer void
reference void
iterator_category std::output_iterator_tag

Member functions


                      constructs a new ostream_joiner
constructor (public member function)


destructor destructs an ostream_joiner
                      (public member function)
(implicitly declared)
                      writes a object to the associated output sequence
operator= (public member function)
                      no-op
operator* (public member function)
                      no-op
operator++ (public member function)
operator++(int)

Non-member functions


                    creates a ostream_joiner object, deducing the template's type arguments from the function arguments
make_ostream_joiner (function template)

Example


// Run this code


  #include <algorithm>
  #include <experimental/iterator>
  #include <iostream>
  #include <iterator>


  int main()
  {
      int i[] = {1, 2, 3, 4, 5};
      std::copy(std::begin(i),
                std::end(i),
                std::experimental::make_ostream_joiner(std::cout, ", "));
  }

Output:


  1, 2, 3, 4, 5

See also


                    output iterator that writes to std::basic_streambuf
ostreambuf_iterator (class template)
                    output iterator that writes to std::basic_ostream
ostream_iterator (class template)
                    input iterator that reads from std::basic_istream
istream_iterator (class template)