14#ifndef RANGES_V3_ITERATOR_STREAM_ITERATORS_HPP
15#define RANGES_V3_ITERATOR_STREAM_ITERATORS_HPP
28#include <range/v3/detail/prologue.hpp>
34 template<
typename T = void,
typename Char = char,
35 typename Traits = std::char_traits<Char>>
36 struct ostream_iterator
43 using difference_type = std::ptrdiff_t;
44 using char_type = Char;
45 using traits_type = Traits;
46 using ostream_type = std::basic_ostream<Char, Traits>;
48 constexpr ostream_iterator() =
default;
49 ostream_iterator(ostream_type & s, Char
const * d =
nullptr) noexcept
54 requires convertible_to<U, value_t<U>
const &>)
55 ostream_iterator & operator=(U && value)
58 *sout_ << static_cast<value_t<U>
const &>(
static_cast<U &&
>(value));
63 ostream_iterator & operator*()
67 ostream_iterator & operator++()
71 ostream_iterator & operator++(
int)
81 template<
typename Delim,
typename Char = char,
82 typename Traits = std::char_traits<Char>>
85 CPP_assert(semiregular<Delim>);
86 using difference_type = std::ptrdiff_t;
87 using char_type = Char;
88 using traits_type = Traits;
89 using ostream_type = std::basic_ostream<Char, Traits>;
91 constexpr ostream_joiner() =
default;
92 ostream_joiner(ostream_type & s, Delim
const & d)
94 , sout_(std::addressof(s))
97 ostream_joiner(ostream_type & s, Delim && d)
98 : delim_(std::move(d))
99 , sout_(std::addressof(s))
103 ostream_joiner & operator=(T
const & value)
105 RANGES_EXPECT(sout_);
112 ostream_joiner & operator*()
noexcept
116 ostream_joiner & operator++()
noexcept
120 ostream_joiner & operator++(
int)
noexcept
127 ostream_type * sout_;
133 template(
typename Delim,
typename Char,
typename Traits)(
134 requires semiregular<detail::decay_t<Delim>>)
136 operator()(std::basic_ostream<Char, Traits> & s, Delim && d)
const
138 return {s, std::forward<Delim>(d)};
145 template<
typename Char,
typename Traits = std::
char_traits<Char>>
146 struct ostreambuf_iterator
149 typedef ptrdiff_t difference_type;
150 typedef Char char_type;
151 typedef Traits traits_type;
152 typedef std::basic_streambuf<Char, Traits> streambuf_type;
153 typedef std::basic_ostream<Char, Traits> ostream_type;
155 constexpr ostreambuf_iterator() =
default;
156 ostreambuf_iterator(ostream_type & s) noexcept
157 : ostreambuf_iterator(s.rdbuf())
159 ostreambuf_iterator(streambuf_type * s) noexcept
162 RANGES_ASSERT(s !=
nullptr);
164 ostreambuf_iterator & operator=(Char c)
166 RANGES_ASSERT(sbuf_ !=
nullptr);
168 failed_ = (sbuf_->sputc(c) == Traits::eof());
171 ostreambuf_iterator & operator*()
175 ostreambuf_iterator & operator++()
179 ostreambuf_iterator & operator++(
int)
183 bool failed()
const noexcept
189 streambuf_type * sbuf_ =
nullptr;
190 bool failed_ =
false;
195 template<
typename T,
typename Char = char,
196 typename Traits = std::char_traits<Char>>
206 template<
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
207 class unformatted_ostream_iterator final
210 using iterator_category = std::output_iterator_tag;
211 using difference_type = std::ptrdiff_t;
212 using char_type = CharT;
213 using traits_type = Traits;
214 using ostream_type = std::basic_ostream<CharT, Traits>;
216 unformatted_ostream_iterator() =
default;
218 explicit unformatted_ostream_iterator(ostream_type & out) noexcept
224 unformatted_ostream_iterator & operator=(T
const & t)
227 out_->write(
reinterpret_cast<char const *
>(std::addressof(t)),
sizeof(T));
231 unformatted_ostream_iterator & operator*()
noexcept
235 unformatted_ostream_iterator & operator++()
noexcept
239 unformatted_ostream_iterator & operator++(
int)
noexcept
245 ostream_type * out_ =
nullptr;
251RANGES_DIAGNOSTIC_PUSH
252RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS
256 template<
typename T,
typename Char,
typename Traits>
258 : ::ranges::detail::std_output_iterator_traits<>
261 template<
typename Char,
typename Traits>
262 struct iterator_traits<::ranges::ostreambuf_iterator<Char, Traits>>
263 : ::ranges::detail::std_output_iterator_traits<>
270#include <range/v3/detail/epilogue.hpp>
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector > >, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition conversion.hpp:399
_t< detail::_if_< list< Args... > > > if_
Select one type or another depending on a compile-time Boolean.
Definition meta.hpp:1247
Definition adjacent_find.hpp:67
Definition stream_iterators.hpp:132
Definition stream_iterators.hpp:37
Definition stream_iterators.hpp:84
Definition stream_iterators.hpp:147