blob: a5e3dffba980bca1a6c1198ae3ff217d29605af0 [file] [log] [blame]
Andrew Top61a84952019-04-30 15:07:33 -07001// -*- C++ -*-
Kaido Kert788710a2023-06-05 07:50:22 -07002//===----------------------------------------------------------------------===//
Andrew Top61a84952019-04-30 15:07:33 -07003//
Kaido Kert788710a2023-06-05 07:50:22 -07004// 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
Andrew Top61a84952019-04-30 15:07:33 -07007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_EXPERIMENTAL_ITERATOR
11#define _LIBCPP_EXPERIMENTAL_ITERATOR
12
13/*
14namespace std {
15 namespace experimental {
16 inline namespace fundamentals_v2 {
17
18 template <class DelimT, class charT = char, class traits = char_traits<charT>>
19 class ostream_joiner {
20 public:
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;
27 typedef void pointer;
28 typedef void reference;
Kaido Kert788710a2023-06-05 07:50:22 -070029
Andrew Top61a84952019-04-30 15:07:33 -070030 ostream_joiner(ostream_type& s, const DelimT& delimiter);
31 ostream_joiner(ostream_type& s, DelimT&& delimiter);
32
Kaido Kert788710a2023-06-05 07:50:22 -070033 template<typename T>
Andrew Top61a84952019-04-30 15:07:33 -070034 ostream_joiner& operator=(const T& value);
35
36 ostream_joiner& operator*() noexcept;
37 ostream_joiner& operator++() noexcept;
38 ostream_joiner& operator++(int) noexcept;
39 private:
Kaido Kert788710a2023-06-05 07:50:22 -070040 ostream_type* out_stream; // exposition only
41 DelimT delim; // exposition only
Andrew Top61a84952019-04-30 15:07:33 -070042 bool first_element; // exposition only
43 };
44
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);
48
49 } // inline namespace fundamentals_v2
50 } // namespace experimental
51} // namespace std
52
53*/
54
Kaido Kert788710a2023-06-05 07:50:22 -070055#include <__assert> // all public C++ headers provide the assertion handler
56#include <__memory/addressof.h>
57#include <__type_traits/decay.h>
58#include <__utility/forward.h>
59#include <__utility/move.h>
Andrew Top61a84952019-04-30 15:07:33 -070060#include <experimental/__config>
Kaido Kert788710a2023-06-05 07:50:22 -070061#include <iosfwd> // char_traits
62#include <iterator>
63
64#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65# pragma GCC system_header
66#endif
Andrew Top61a84952019-04-30 15:07:33 -070067
Kaido Kert56d7c4e2024-04-13 12:59:27 -070068#if _LIBCPP_STD_VER >= 14
Andrew Top61a84952019-04-30 15:07:33 -070069
Andrew Top61a84952019-04-30 15:07:33 -070070_LIBCPP_BEGIN_NAMESPACE_LFTS
71
72template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
73class ostream_joiner {
74public:
75
76 typedef _CharT char_type;
77 typedef _Traits traits_type;
78 typedef basic_ostream<char_type,traits_type> ostream_type;
79 typedef output_iterator_tag iterator_category;
80 typedef void value_type;
81 typedef void difference_type;
82 typedef void pointer;
83 typedef void reference;
84
Kaido Kert25902c62024-06-17 17:10:28 -070085 _LIBCPP_HIDE_FROM_ABI ostream_joiner(ostream_type& __os, _Delim&& __d)
Kaido Kert788710a2023-06-05 07:50:22 -070086 : __output_iter_(_VSTD::addressof(__os)), __delim_(_VSTD::move(__d)), __first_(true) {}
87
Kaido Kert25902c62024-06-17 17:10:28 -070088 _LIBCPP_HIDE_FROM_ABI ostream_joiner(ostream_type& __os, const _Delim& __d)
Kaido Kert788710a2023-06-05 07:50:22 -070089 : __output_iter_(_VSTD::addressof(__os)), __delim_(__d), __first_(true) {}
90
Andrew Top61a84952019-04-30 15:07:33 -070091
92 template<typename _Tp>
Kaido Kert25902c62024-06-17 17:10:28 -070093 _LIBCPP_HIDE_FROM_ABI ostream_joiner& operator=(const _Tp& __v)
Andrew Top61a84952019-04-30 15:07:33 -070094 {
Kaido Kert788710a2023-06-05 07:50:22 -070095 if (!__first_)
96 *__output_iter_ << __delim_;
97 __first_ = false;
98 *__output_iter_ << __v;
Andrew Top61a84952019-04-30 15:07:33 -070099 return *this;
100 }
101
Kaido Kert25902c62024-06-17 17:10:28 -0700102 _LIBCPP_HIDE_FROM_ABI ostream_joiner& operator*() _NOEXCEPT { return *this; }
103 _LIBCPP_HIDE_FROM_ABI ostream_joiner& operator++() _NOEXCEPT { return *this; }
104 _LIBCPP_HIDE_FROM_ABI ostream_joiner& operator++(int) _NOEXCEPT { return *this; }
Andrew Top61a84952019-04-30 15:07:33 -0700105
106private:
Kaido Kert788710a2023-06-05 07:50:22 -0700107 ostream_type* __output_iter_;
108 _Delim __delim_;
109 bool __first_;
Andrew Top61a84952019-04-30 15:07:33 -0700110};
111
112
113template <class _CharT, class _Traits, class _Delim>
Kaido Kert56d7c4e2024-04-13 12:59:27 -0700114_LIBCPP_HIDE_FROM_ABI ostream_joiner<__decay_t<_Delim>, _CharT, _Traits>
Andrew Top61a84952019-04-30 15:07:33 -0700115make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
Kaido Kert56d7c4e2024-04-13 12:59:27 -0700116{ return ostream_joiner<__decay_t<_Delim>, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); }
Andrew Top61a84952019-04-30 15:07:33 -0700117
118_LIBCPP_END_NAMESPACE_LFTS
119
Kaido Kert56d7c4e2024-04-13 12:59:27 -0700120#endif // _LIBCPP_STD_VER >= 14
Kaido Kert788710a2023-06-05 07:50:22 -0700121
122#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
123# include <type_traits>
124#endif
Andrew Top61a84952019-04-30 15:07:33 -0700125
126#endif // _LIBCPP_EXPERIMENTAL_ITERATOR