Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

116 lines
3.5KB

  1. // <experimental/iterator> -*- C++ -*-
  2. // Copyright (C) 2015-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file experimental/iterator
  21. * This is a TS C++ Library header.
  22. * @ingroup libfund-ts
  23. */
  24. //
  25. // N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2
  26. //
  27. #ifndef _GLIBCXX_EXPERIMENTAL_ITERATOR
  28. #define _GLIBCXX_EXPERIMENTAL_ITERATOR 1
  29. #pragma GCC system_header
  30. #if __cplusplus >= 201402L
  31. #include <iterator>
  32. #include <iosfwd>
  33. #include <experimental/type_traits>
  34. namespace std _GLIBCXX_VISIBILITY(default)
  35. {
  36. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  37. namespace experimental
  38. {
  39. inline namespace fundamentals_v2
  40. {
  41. #define __cpp_lib_experimental_ostream_joiner 201411
  42. /// Output iterator that inserts a delimiter between elements.
  43. template<typename _DelimT, typename _CharT = char,
  44. typename _Traits = char_traits<_CharT>>
  45. class ostream_joiner
  46. {
  47. public:
  48. typedef _CharT char_type;
  49. typedef _Traits traits_type;
  50. typedef basic_ostream<_CharT, _Traits> ostream_type;
  51. typedef output_iterator_tag iterator_category;
  52. typedef void value_type;
  53. typedef void difference_type;
  54. typedef void pointer;
  55. typedef void reference;
  56. ostream_joiner(ostream_type& __os, const _DelimT& __delimiter)
  57. noexcept(is_nothrow_copy_constructible_v<_DelimT>)
  58. : _M_out(std::__addressof(__os)), _M_delim(__delimiter)
  59. { }
  60. ostream_joiner(ostream_type& __os, _DelimT&& __delimiter)
  61. noexcept(is_nothrow_move_constructible_v<_DelimT>)
  62. : _M_out(std::__addressof(__os)), _M_delim(std::move(__delimiter))
  63. { }
  64. template<typename _Tp>
  65. ostream_joiner&
  66. operator=(const _Tp& __value)
  67. {
  68. if (!_M_first)
  69. *_M_out << _M_delim;
  70. _M_first = false;
  71. *_M_out << __value;
  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* _M_out;
  79. _DelimT _M_delim;
  80. bool _M_first = true;
  81. };
  82. /// Object generator for ostream_joiner.
  83. template<typename _CharT, typename _Traits, typename _DelimT>
  84. inline ostream_joiner<decay_t<_DelimT>, _CharT, _Traits>
  85. make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os,
  86. _DelimT&& __delimiter)
  87. { return { __os, std::forward<_DelimT>(__delimiter) }; }
  88. } // namespace fundamentals_v2
  89. } // namespace experimental
  90. _GLIBCXX_END_NAMESPACE_VERSION
  91. } // namespace std
  92. #endif // __cplusplus <= 201103L
  93. #endif // _GLIBCXX_EXPERIMENTAL_ITERATOR