1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H
11 #define _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H
12 
13 #include <__config>
14 #include <__iterator/iterator_traits.h>
15 #include <__iterator/iterator.h>
16 #include <__memory/addressof.h>
17 #include <cstddef>
18 #include <iosfwd> // for forward declarations of char_traits and basic_ostream
19 
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #pragma GCC system_header
22 #endif
23 
24 _LIBCPP_PUSH_MACROS
25 #include <__undef_macros>
26 
27 _LIBCPP_BEGIN_NAMESPACE_STD
28 
29 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
30 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
31 class _LIBCPP_TEMPLATE_VIS ostream_iterator
32 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
33     : public iterator<output_iterator_tag, void, void, void, void>
34 #endif
35 {
36 _LIBCPP_SUPPRESS_DEPRECATED_POP
37 public:
38     typedef output_iterator_tag             iterator_category;
39     typedef void                            value_type;
40 #if _LIBCPP_STD_VER > 17
41     typedef ptrdiff_t                       difference_type;
42 #else
43     typedef void                            difference_type;
44 #endif
45     typedef void                            pointer;
46     typedef void                            reference;
47     typedef _CharT                          char_type;
48     typedef _Traits                         traits_type;
49     typedef basic_ostream<_CharT, _Traits>  ostream_type;
50 
51 private:
52     ostream_type* __out_stream_;
53     const char_type* __delim_;
54 public:
55     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
56         : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
57     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
58         : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
59     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
60         {
61             *__out_stream_ << __value_;
62             if (__delim_)
63                 *__out_stream_ << __delim_;
64             return *this;
65         }
66 
67     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
68     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
69     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
70 };
71 
72 _LIBCPP_END_NAMESPACE_STD
73 
74 _LIBCPP_POP_MACROS
75 
76 #endif // _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H
77