libstdc++
|
00001 // <experimental/iterator> -*- C++ -*- 00002 00003 // Copyright (C) 2015-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file experimental/iterator 00026 * This is a TS C++ Library header. 00027 */ 00028 00029 // 00030 // N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2 00031 // 00032 00033 #ifndef _GLIBCXX_EXPERIMENTAL_ITERATOR 00034 #define _GLIBCXX_EXPERIMENTAL_ITERATOR 1 00035 00036 #pragma GCC system_header 00037 00038 #if __cplusplus >= 201402L 00039 00040 #include <iterator> 00041 #include <iosfwd> 00042 #include <experimental/type_traits> 00043 00044 namespace std _GLIBCXX_VISIBILITY(default) 00045 { 00046 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00047 00048 namespace experimental 00049 { 00050 inline namespace fundamentals_v2 00051 { 00052 #define __cpp_lib_experimental_ostream_joiner 201411 00053 00054 /// Output iterator that inserts a delimiter between elements. 00055 template<typename _DelimT, typename _CharT = char, 00056 typename _Traits = char_traits<_CharT>> 00057 class ostream_joiner 00058 { 00059 public: 00060 typedef _CharT char_type; 00061 typedef _Traits traits_type; 00062 typedef basic_ostream<_CharT, _Traits> ostream_type; 00063 typedef output_iterator_tag iterator_category; 00064 typedef void value_type; 00065 typedef void difference_type; 00066 typedef void pointer; 00067 typedef void reference; 00068 00069 ostream_joiner(ostream_type& __os, const _DelimT& __delimiter) 00070 noexcept(is_nothrow_copy_constructible_v<_DelimT>) 00071 : _M_out(std::__addressof(__os)), _M_delim(__delimiter) 00072 { } 00073 00074 ostream_joiner(ostream_type& __os, _DelimT&& __delimiter) 00075 noexcept(is_nothrow_move_constructible_v<_DelimT>) 00076 : _M_out(std::__addressof(__os)), _M_delim(std::move(__delimiter)) 00077 { } 00078 00079 template<typename _Tp> 00080 ostream_joiner& 00081 operator=(const _Tp& __value) 00082 { 00083 if (!_M_first) 00084 *_M_out << _M_delim; 00085 _M_first = false; 00086 *_M_out << __value; 00087 return *this; 00088 } 00089 00090 ostream_joiner& operator*() noexcept { return *this; } 00091 ostream_joiner& operator++() noexcept { return *this; } 00092 ostream_joiner& operator++(int) noexcept { return *this; } 00093 00094 private: 00095 ostream_type* _M_out; 00096 _DelimT _M_delim; 00097 bool _M_first = true; 00098 }; 00099 00100 /// Object generator for ostream_joiner. 00101 template<typename _CharT, typename _Traits, typename _DelimT> 00102 inline ostream_joiner<decay_t<_DelimT>, _CharT, _Traits> 00103 make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, 00104 _DelimT&& __delimiter) 00105 { return { __os, std::forward<_DelimT>(__delimiter) }; } 00106 } // namespace fundamentals_v2 00107 } // namespace experimental 00108 00109 _GLIBCXX_END_NAMESPACE_VERSION 00110 } // namespace std 00111 00112 #endif // __cplusplus <= 201103L 00113 00114 #endif // _GLIBCXX_EXPERIMENTAL_ITERATOR