mirror of
https://github.com/boostorg/io.git
synced 2025-07-30 04:17:13 +02:00
Implement ostream_joiner
This commit is contained in:
5
doc/io-docinfo-footer.html
Normal file
5
doc/io-docinfo-footer.html
Normal file
@ -0,0 +1,5 @@
|
||||
<style>
|
||||
.specification {
|
||||
margin-left: 2em;
|
||||
}
|
||||
</style>
|
@ -7,7 +7,8 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
////
|
||||
|
||||
# Boost.IO
|
||||
Daryle Walker, Beman Dawes
|
||||
Daryle Walker, Beman Dawes, Glen Joseph Fernandes <glenjofe@gmail.com>
|
||||
:docinfo: private-footer
|
||||
:idprefix:
|
||||
:source-language: cpp
|
||||
:toc: left
|
||||
@ -19,6 +20,7 @@ library.
|
||||
:leveloffset: +1
|
||||
|
||||
include::ios_state.adoc[]
|
||||
include::ostream_joiner.adoc[]
|
||||
|
||||
:leveloffset: -1
|
||||
|
||||
|
143
doc/ostream_joiner.adoc
Normal file
143
doc/ostream_joiner.adoc
Normal file
@ -0,0 +1,143 @@
|
||||
////
|
||||
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)
|
||||
////
|
||||
|
||||
# ostream_joiner, <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`.
|
Reference in New Issue
Block a user