2 //===----------------------------- iterator -------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_EXPERIMENTAL_ITERATOR
11 #define _LIBCPP_EXPERIMENTAL_ITERATOR
15 namespace experimental {
16 inline namespace fundamentals_v2 {
18 template <class DelimT, class charT = char, class traits = char_traits<charT>>
19 class ostream_joiner {
21 typedef charT char_type;
22 typedef traits traits_type;
23 typedef basic_ostream<charT, traits> ostream_type;
24 typedef output_iterator_tag iterator_category;
25 typedef void value_type;
26 typedef void difference_type;
28 typedef void reference;
30 ostream_joiner(ostream_type& s, const DelimT& delimiter);
31 ostream_joiner(ostream_type& s, DelimT&& delimiter);
34 ostream_joiner& operator=(const T& value);
36 ostream_joiner& operator*() noexcept;
37 ostream_joiner& operator++() noexcept;
38 ostream_joiner& operator++(int) noexcept;
40 ostream_type* out_stream; // exposition only
41 DelimT delim; // exposition only
42 bool first_element; // exposition only
45 template <class charT, class traits, class DelimT>
46 ostream_joiner<decay_t<DelimT>, charT, traits>
47 make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
49 } // inline namespace fundamentals_v2
50 } // namespace experimental
55 #include <experimental/__config>
57 #if _LIBCPP_STD_VER > 11
61 _LIBCPP_BEGIN_NAMESPACE_LFTS
63 template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
64 class ostream_joiner {
67 typedef _CharT char_type;
68 typedef _Traits traits_type;
69 typedef basic_ostream<char_type,traits_type> ostream_type;
70 typedef output_iterator_tag iterator_category;
71 typedef void value_type;
72 typedef void difference_type;
74 typedef void reference;
76 ostream_joiner(ostream_type& __os, _Delim&& __d)
77 : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {}
79 ostream_joiner(ostream_type& __os, const _Delim& __d)
80 : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {}
83 template<typename _Tp>
84 ostream_joiner& operator=(const _Tp& __v)
87 *__output_iter << __delim;
89 *__output_iter << __v;
93 ostream_joiner& operator*() _NOEXCEPT { return *this; }
94 ostream_joiner& operator++() _NOEXCEPT { return *this; }
95 ostream_joiner& operator++(int) _NOEXCEPT { return *this; }
98 ostream_type* __output_iter;
104 template <class _CharT, class _Traits, class _Delim>
105 ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>
106 make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
107 { return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); }
109 _LIBCPP_END_NAMESPACE_LFTS
111 #endif /* _LIBCPP_STD_VER > 11 */
113 #endif // _LIBCPP_EXPERIMENTAL_ITERATOR