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