brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · fb77c67 Raw
87 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___CXX03___ITERATOR_ISTREAM_ITERATOR_H11#define _LIBCPP___CXX03___ITERATOR_ISTREAM_ITERATOR_H12 13#include <__cxx03/__config>14#include <__cxx03/__fwd/istream.h>15#include <__cxx03/__fwd/string.h>16#include <__cxx03/__iterator/iterator.h>17#include <__cxx03/__iterator/iterator_traits.h>18#include <__cxx03/__memory/addressof.h>19#include <__cxx03/cstddef>20 21#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)22#  pragma GCC system_header23#endif24 25_LIBCPP_BEGIN_NAMESPACE_STD26 27_LIBCPP_SUPPRESS_DEPRECATED_PUSH28template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>29class _LIBCPP_TEMPLATE_VIS istream_iterator30    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> {31  _LIBCPP_SUPPRESS_DEPRECATED_POP32 33public:34  typedef input_iterator_tag iterator_category;35  typedef _Tp value_type;36  typedef _Distance difference_type;37  typedef const _Tp* pointer;38  typedef const _Tp& reference;39  typedef _CharT char_type;40  typedef _Traits traits_type;41  typedef basic_istream<_CharT, _Traits> istream_type;42 43private:44  istream_type* __in_stream_;45  _Tp __value_;46 47public:48  _LIBCPP_HIDE_FROM_ABI istream_iterator() : __in_stream_(nullptr), __value_() {}49  _LIBCPP_HIDE_FROM_ABI istream_iterator(istream_type& __s) : __in_stream_(std::addressof(__s)) {50    if (!(*__in_stream_ >> __value_))51      __in_stream_ = nullptr;52  }53 54  _LIBCPP_HIDE_FROM_ABI const _Tp& operator*() const { return __value_; }55  _LIBCPP_HIDE_FROM_ABI const _Tp* operator->() const { return std::addressof((operator*())); }56  _LIBCPP_HIDE_FROM_ABI istream_iterator& operator++() {57    if (!(*__in_stream_ >> __value_))58      __in_stream_ = nullptr;59    return *this;60  }61  _LIBCPP_HIDE_FROM_ABI istream_iterator operator++(int) {62    istream_iterator __t(*this);63    ++(*this);64    return __t;65  }66 67  template <class _Up, class _CharU, class _TraitsU, class _DistanceU>68  friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,69                                               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);70};71 72template <class _Tp, class _CharT, class _Traits, class _Distance>73inline _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,74                                             const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) {75  return __x.__in_stream_ == __y.__in_stream_;76}77 78template <class _Tp, class _CharT, class _Traits, class _Distance>79inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,80                                             const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) {81  return !(__x == __y);82}83 84_LIBCPP_END_NAMESPACE_STD85 86#endif // _LIBCPP___CXX03___ITERATOR_ISTREAM_ITERATOR_H87