std::experimental::ostream_joiner

From cppreference.com
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
Defined in header <experimental/iterator>
template <

class DelimT,
class CharT = char,
class Traits = std::char_traits <CharT>
>

class ostream_joiner;
(library fundamentals TS v2)

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<< ostream_joiner

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

Compared to std::ostream_iterator, ostream_joiner

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
(public member function)
(destructor)
(implicitly declared)
destructs an ostream_joiner
(public member function)
writes an object to the associated output sequence
(public member function)
no-op
(public member function)
no-op
(public member function)

Non-member functions

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

Example

#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
(class template)
output iterator that writes to std::basic_ostream
(class template)
input iterator that reads from std::basic_istream
(class template)