iterator 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // -*- C++ -*-
  2. //===----------------------------- iterator -------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is distributed under the University of Illinois Open Source
  7. // License. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_EXPERIMENTAL_ITERATOR
  11. #define _LIBCPP_EXPERIMENTAL_ITERATOR
  12. /*
  13. namespace std {
  14. namespace experimental {
  15. inline namespace fundamentals_v2 {
  16. template <class DelimT, class charT = char, class traits = char_traits<charT>>
  17. class ostream_joiner {
  18. public:
  19. typedef charT char_type;
  20. typedef traits traits_type;
  21. typedef basic_ostream<charT, traits> ostream_type;
  22. typedef output_iterator_tag iterator_category;
  23. typedef void value_type;
  24. typedef void difference_type;
  25. typedef void pointer;
  26. typedef void reference;
  27. ostream_joiner(ostream_type& s, const DelimT& delimiter);
  28. ostream_joiner(ostream_type& s, DelimT&& delimiter);
  29. template<typename T>
  30. ostream_joiner& operator=(const T& value);
  31. ostream_joiner& operator*() noexcept;
  32. ostream_joiner& operator++() noexcept;
  33. ostream_joiner& operator++(int) noexcept;
  34. private:
  35. ostream_type* out_stream; // exposition only
  36. DelimT delim; // exposition only
  37. bool first_element; // exposition only
  38. };
  39. template <class charT, class traits, class DelimT>
  40. ostream_joiner<decay_t<DelimT>, charT, traits>
  41. make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
  42. } // inline namespace fundamentals_v2
  43. } // namespace experimental
  44. } // namespace std
  45. */
  46. #include <experimental/__config>
  47. #if _LIBCPP_STD_VER > 11
  48. #include <iterator>
  49. _LIBCPP_BEGIN_NAMESPACE_LFTS
  50. template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
  51. class ostream_joiner {
  52. public:
  53. typedef _CharT char_type;
  54. typedef _Traits traits_type;
  55. typedef basic_ostream<char_type,traits_type> ostream_type;
  56. typedef output_iterator_tag iterator_category;
  57. typedef void value_type;
  58. typedef void difference_type;
  59. typedef void pointer;
  60. typedef void reference;
  61. ostream_joiner(ostream_type& __os, _Delim&& __d)
  62. : __out(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {}
  63. ostream_joiner(ostream_type& __os, const _Delim& __d)
  64. : __out(_VSTD::addressof(__os)), __delim(__d), __first(true) {}
  65. template<typename _Tp>
  66. ostream_joiner& operator=(const _Tp& __v)
  67. {
  68. if (!__first)
  69. *__out << __delim;
  70. __first = false;
  71. *__out << __v;
  72. return *this;
  73. }
  74. ostream_joiner& operator*() _NOEXCEPT { return *this; }
  75. ostream_joiner& operator++() _NOEXCEPT { return *this; }
  76. ostream_joiner& operator++(int) _NOEXCEPT { return *this; }
  77. private:
  78. ostream_type* __out;
  79. _Delim __delim;
  80. bool __first;
  81. };
  82. template <class _CharT, class _Traits, class _Delim>
  83. ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>
  84. make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
  85. { return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); }
  86. _LIBCPP_END_NAMESPACE_LFTS
  87. #endif /* _LIBCPP_STD_VER > 11 */
  88. #endif // _LIBCPP_EXPERIMENTAL_ITERATOR