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