70 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H11#define _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H12 13#include <__config>14#include <__cstddef/ptrdiff_t.h>15#include <__fwd/ostream.h>16#include <__fwd/string.h>17#include <__iterator/iterator.h>18#include <__iterator/iterator_traits.h>19#include <__memory/addressof.h>20 21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22# pragma GCC system_header23#endif24 25_LIBCPP_BEGIN_NAMESPACE_STD26 27template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >28class ostream_iterator29 : public __iterator_base<ostream_iterator<_Tp, _CharT, _Traits>, output_iterator_tag, void, void, void, void> {30public:31 typedef output_iterator_tag iterator_category;32 typedef void value_type;33#if _LIBCPP_STD_VER >= 2034 typedef ptrdiff_t difference_type;35#else36 typedef void difference_type;37#endif38 typedef void pointer;39 typedef void reference;40 typedef _CharT char_type;41 typedef _Traits traits_type;42 typedef basic_ostream<_CharT, _Traits> ostream_type;43 44private:45 ostream_type* __out_stream_;46 const char_type* __delim_;47 48public:49 _LIBCPP_HIDE_FROM_ABI ostream_iterator(ostream_type& __s) _NOEXCEPT50 : __out_stream_(std::addressof(__s)),51 __delim_(nullptr) {}52 _LIBCPP_HIDE_FROM_ABI ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT53 : __out_stream_(std::addressof(__s)),54 __delim_(__delimiter) {}55 _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator=(const _Tp& __value) {56 *__out_stream_ << __value;57 if (__delim_)58 *__out_stream_ << __delim_;59 return *this;60 }61 62 _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator*() { return *this; }63 _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator++() { return *this; }64 _LIBCPP_HIDE_FROM_ABI ostream_iterator& operator++(int) { return *this; }65};66 67_LIBCPP_END_NAMESPACE_STD68 69#endif // _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H70