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.h> 15 #include <__iterator/iterator_traits.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_BEGIN_NAMESPACE_STD 25 26 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 27 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > 28 class _LIBCPP_TEMPLATE_VIS ostream_iterator 29 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) 30 : public iterator<output_iterator_tag, void, void, void, void> 31 #endif 32 { 33 _LIBCPP_SUPPRESS_DEPRECATED_POP 34 public: 35 typedef output_iterator_tag iterator_category; 36 typedef void value_type; 37 #if _LIBCPP_STD_VER > 17 38 typedef ptrdiff_t difference_type; 39 #else 40 typedef void difference_type; 41 #endif 42 typedef void pointer; 43 typedef void reference; 44 typedef _CharT char_type; 45 typedef _Traits traits_type; 46 typedef basic_ostream<_CharT, _Traits> ostream_type; 47 48 private: 49 ostream_type* __out_stream_; 50 const char_type* __delim_; 51 public: 52 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT 53 : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {} 54 _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT 55 : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} 56 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value) 57 { 58 *__out_stream_ << __value; 59 if (__delim_) 60 *__out_stream_ << __delim_; 61 return *this; 62 } 63 64 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} 65 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} 66 _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} 67 }; 68 69 _LIBCPP_END_NAMESPACE_STD 70 71 #endif // _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H 72