libstdc++
iterator
Go to the documentation of this file.
00001 // <experimental/iterator> -*- C++ -*-
00002 
00003 // Copyright (C) 2015-2016 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 <= 201103L
00039 # include <bits/c++14_warning.h>
00040 #else
00041 
00042 #include <experimental/type_traits>
00043 #include <iosfwd>
00044 #include <bits/move.h>
00045 #include <bits/stl_iterator_base_types.h>
00046 
00047 namespace std _GLIBCXX_VISIBILITY(default)
00048 {
00049 namespace experimental
00050 {
00051 inline namespace fundamentals_v2
00052 {
00053 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00054 
00055 #define __cpp_lib_experimental_ostream_joiner 201411
00056 
00057   /// Output iterator that inserts a delimiter between elements.
00058   template<typename _DelimT, typename _CharT = char,
00059            typename _Traits = char_traits<_CharT>>
00060   class ostream_joiner
00061   {
00062   public:
00063     typedef _CharT                              char_type;
00064     typedef _Traits                             traits_type;
00065     typedef basic_ostream<_CharT, _Traits>      ostream_type;
00066     typedef output_iterator_tag                 iterator_category;
00067     typedef void                                value_type;
00068     typedef void                                difference_type;
00069     typedef void                                pointer;
00070     typedef void                                reference;
00071 
00072     ostream_joiner(ostream_type& __os, const _DelimT& __delimiter)
00073     noexcept(is_nothrow_copy_constructible_v<_DelimT>)
00074     : _M_out(std::__addressof(__os)), _M_delim(__delimiter)
00075     { }
00076 
00077     ostream_joiner(ostream_type& __os, _DelimT&& __delimiter)
00078     noexcept(is_nothrow_move_constructible_v<_DelimT>)
00079     : _M_out(std::__addressof(__os)), _M_delim(std::move(__delimiter))
00080     { }
00081 
00082     template<typename _Tp>
00083       ostream_joiner&
00084       operator=(const _Tp& __value)
00085       {
00086         if (!_M_first)
00087           *_M_out << _M_delim;
00088         _M_first = false;
00089         *_M_out << __value;
00090         return *this;
00091       }
00092 
00093     ostream_joiner& operator*() noexcept { return *this; }
00094     ostream_joiner& operator++() noexcept { return *this; }
00095     ostream_joiner& operator++(int) noexcept { return *this; }
00096 
00097   private:
00098     ostream_type* _M_out;
00099     _DelimT _M_delim;
00100     bool _M_first = true;
00101   };
00102 
00103   /// Object generator for ostream_joiner.
00104   template<typename _CharT, typename _Traits, typename _DelimT>
00105     inline ostream_joiner<decay_t<_DelimT>, _CharT, _Traits>
00106     make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os,
00107                         _DelimT&& __delimiter)
00108     { return { __os, std::forward<_DelimT>(__delimiter) }; }
00109 
00110 _GLIBCXX_END_NAMESPACE_VERSION
00111 } // namespace fundamentals_v2
00112 } // namespace experimental
00113 } // namespace std
00114 
00115 #endif // __cplusplus <= 201103L
00116 
00117 #endif // _GLIBCXX_EXPERIMENTAL_ITERATOR