1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
////
Copyright 2019 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
////
# Delimited Iterators, <boost/io/ostream_joiner.hpp>
:toc:
:toc-title:
:idprefix:
## Description
The header `<boost/io/ostream_joiner.hpp>` provides the class template
`boost::io::ostream_joiner` which is an output iterator that writes objects to
a `std::basic_ostream` separated by a delimiter. It is an implementation of
the Library Fundamentals TS `std::ostream_joiner` which supports {cpp}03 and
higher.
## Example
The following program writes the contents of a vector to standard output, with
each element separated by a comma.
```
#include <boost/io/ostream_joiner.hpp>
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v;
v.push_back(2);
v.push_back(4);
v.push_back(6);
v.push_back(8);
std::copy(v.begin(), v.end(), boost::make_ostream_joiner(std::cout, ','));
}
```
## Reference
### Header Synopsis
```
namespace boost {
namespace io {
template<class Delim, class Char = char,
class Traits = std::char_traits<Char> >
class ostream_joiner {
public:
typedef Char char_type;
typedef Traits traits_type;
typedef std::basic_ostream<Char, Traits> ostream_type;
typedef std::output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
ostream_joiner(ostream_type& output, const Delim& delim);
ostream_joiner(ostream_type& output, Delim&& delim);
template<class T>
ostream_joiner& operator=(const T& value);
ostream_joiner& operator*() noexcept;
ostream_joiner& operator++() noexcept;
ostream_joiner& operator++(int) noexcept;
};
template<class Char, class Traits, class Delim>
ostream_joiner<std::decay_t<Delim>, Char, Traits>
make_ostream_joiner(std::basic_ostream<Char, Traits>& output, Delim&& delim);
} // io
} // boost
```
### Constructors
```
ostream_joiner(ostream_type& output, const Delim& delim);
```
[.specification]
EFfects:: Initializes the stored reference to the stream with
`std::addressof(output)` and the stored delimiter with `delim`.
```
ostream_joiner(ostream_type& output, Delim&& delim);
```
[.specification]
EFfects:: Initializes the stored reference to the stream with
`std::addressof(output)` and the stored delimiter with `std::move(delim)`.
### Member functions
```
template<class T>
ostream_joiner& operator=(const T& value);
```
[.specification]
Effects:: If the is the first call to this member function, write the stored
delimiter to the stored stream reference. Writes `value` to the stored stream
reference.
Returns:: `*this`.
```
ostream_joiner& operator*() noexcept;
```
```
ostream_joiner& operator++() noexcept;
```
```
ostream_joiner& operator++(int) noexcept;
```
[.specification]
Returns:: `*this`.
### Free functions
```
template<class Char, class Traits, class Delim>
ostream_joiner<decay_t<Delim>, Char, Traits>
make_ostream_joiner(std::basic_ostream<Char, Traits>& output, Delim&& delim);
```
[.specification]
Returns:: `ostream_joiner<std::decay_t<Delim>, Char, Traits>(output,
std::forward<Delim>(delim))`.
## Acknowledgments
Glen Fernandes implemented `ostream_joiner` and `make_ostream_joiner`.
|