From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59957 invoked by alias); 2 May 2015 17:14:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 59889 invoked by uid 89); 2 May 2015 17:14:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 02 May 2015 17:14:35 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t42HEYA7026828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 2 May 2015 13:14:34 -0400 Received: from localhost (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t42HEXnE025400; Sat, 2 May 2015 13:14:34 -0400 Date: Sat, 02 May 2015 17:14:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [patch] std::experimental::ostream_joiner Message-ID: <20150502171433.GB3618@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Edk6HoYKP7RsK9ib" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-05/txt/msg00144.txt.bz2 --Edk6HoYKP7RsK9ib Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Content-length: 197 The last piece of the Library Fundamentals 2 TS (until next week when all of v1 gets voted into v2, when it will include the v1 stuff we're missing). Tested powerpc64le-linux, committed to trunk. --Edk6HoYKP7RsK9ib Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" Content-length: 12046 commit d4a0512671d1a727905afe8efb2798fa630e19b5 Author: Jonathan Wakely Date: Sat May 2 17:19:16 2015 +0100 * include/experimental/iterator: New. Define ostream_joiner. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * testsuite/experimental/iterator/make_ostream_joiner.cc: New. * testsuite/experimental/iterator/ostream_joiner.cc: New. * testsuite/experimental/iterator/requirements.cc: New. * doc/xml/manual/status_cxx2017.xml: Update status. * doc/html/manual/status.html: Regenerate. diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index c30bf09..ee32a2b 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml @@ -220,14 +220,13 @@ not in any particular release. - - - N4257 + + N4066 Delimited iterators - N + Y Library Fundamentals 2 TS diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 92b386a..06a4805 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -651,6 +651,7 @@ experimental_headers = \ ${experimental_srcdir}/erase_if.h \ ${experimental_srcdir}/forward_list \ ${experimental_srcdir}/functional \ + ${experimental_srcdir}/iterator \ ${experimental_srcdir}/list \ ${experimental_srcdir}/map \ ${experimental_srcdir}/memory \ diff --git a/libstdc++-v3/include/experimental/iterator b/libstdc++-v3/include/experimental/iterator new file mode 100644 index 0000000..027043a --- /dev/null +++ b/libstdc++-v3/include/experimental/iterator @@ -0,0 +1,127 @@ +// -*- C++ -*- + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file experimental/iterator + * This is a TS C++ Library header. + */ + +// +// N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2 +// + +#ifndef _GLIBCXX_EXPERIMENTAL_ITERATOR +#define _GLIBCXX_EXPERIMENTAL_ITERATOR 1 + +#pragma GCC system_header + +#if __cplusplus <= 201103L +# include +#else + +#include +#include +#include +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace experimental +{ +inline namespace fundamentals_v2 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#define __cpp_lib_experimental_ostream_joiner 201411 + + /// Output iterator that inserts a delimiter between elements. + template> + class ostream_joiner + { + public: + typedef _CharT char_type; + typedef _Traits traits_type; + typedef basic_ostream<_CharT, _Traits> ostream_type; + typedef output_iterator_tag iterator_category; + typedef void value_type; + typedef void difference_type; + typedef void pointer; + typedef void reference; + + ostream_joiner(ostream_type& __os, const _DelimT& __delimiter) + noexcept(is_nothrow_copy_constructible_v<_DelimT>) + : _M_out(std::__addressof(__os)), _M_delim(__delimiter) + { } + + ostream_joiner(ostream_type& __os, _DelimT&& __delimiter) + noexcept(is_nothrow_move_constructible_v<_DelimT>) + : _M_out(std::__addressof(__os)), _M_delim(std::move(__delimiter)) + { } + + template + ostream_joiner<_DelimT, _CharT, _Traits>& + operator=(const _Tp& __value) + { + if (!_M_first) + *_M_out << _M_delim; + _M_first = false; + *_M_out << __value; + return *this; + } + + ostream_joiner<_DelimT, _CharT, _Traits>& + operator*() noexcept + { return *this; } + + ostream_joiner<_DelimT, _CharT, _Traits>& + operator++() noexcept + { return *this; } + + ostream_joiner<_DelimT, _CharT, _Traits>& + operator++(int) noexcept + { return *this; } + + private: + basic_ostream<_CharT, _Traits>* _M_out; + _DelimT _M_delim; + bool _M_first = true; + }; + + /// Object generator for ostream_joiner. + template + inline ostream_joiner, _CharT, _Traits> + make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, + _DelimT&& __delimiter) + { + return { __os, std::forward<_DelimT>(__delimiter) }; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace fundamentals_v2 +} // namespace experimental +} // namespace std + +#endif // __cplusplus <= 201103L + +#endif // _GLIBCXX_EXPERIMENTAL_ITERATOR diff --git a/libstdc++-v3/testsuite/experimental/iterator/make_ostream_joiner.cc b/libstdc++-v3/testsuite/experimental/iterator/make_ostream_joiner.cc new file mode 100644 index 0000000..76d3a97 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/iterator/make_ostream_joiner.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++14" } + +#include +#include +#include + +void +test01() +{ + std::ostringstream os; + auto joiner = std::experimental::make_ostream_joiner(os, "..."); + for (int i : { 1, 2, 3, 4, 5 }) + *joiner++ = i; + VERIFY( os.str() == "1...2...3...4...5" ); +} + +int +main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/experimental/iterator/ostream_joiner.cc b/libstdc++-v3/testsuite/experimental/iterator/ostream_joiner.cc new file mode 100644 index 0000000..c78dbe6 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/iterator/ostream_joiner.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++14" } + +#include +#include +#include + +#ifndef __cpp_lib_experimental_ostream_joiner +# error Feature-test macro is not defined. +#elif __cpp_lib_experimental_ostream_joiner < 201411 +# error Feature-test macro has bad value. +#endif + +using std::experimental::ostream_joiner; + +void +test01() +{ + std::ostringstream os; + ostream_joiner joiner{os, 9}; + for (int i : { 1, 2, 3, 4, 5 }) + *joiner++ = i; + VERIFY( os.str() == "192939495" ); +} + +void +test02() +{ + std::ostringstream os; + ostream_joiner joiner{os, ','}; + for (int i : { 1, 2, 3, 4, 5 }) + { + *joiner = i; + ++joiner; + } + VERIFY( os.str() == "1,2,3,4,5" ); +} + +void +test03() +{ +#if _GLIBCXX_USE_WCHAR_T + std::wostringstream os; + ostream_joiner joiner{os, L','}; + for (int i : { 1, 2, 3, 4, 5 }) + *joiner++ = i; + VERIFY( os.str() == L"1,2,3,4,5" ); +#endif +} + +int +main() +{ + test01(); + test02(); + test03(); +} diff --git a/libstdc++-v3/testsuite/experimental/iterator/requirements.cc b/libstdc++-v3/testsuite/experimental/iterator/requirements.cc new file mode 100644 index 0000000..54a7f8e --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/iterator/requirements.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// This is a compile-only test with minimal includes +#include +#include + +using namespace std::experimental; + +template +struct tester +{ + using joiner_type = ostream_joiner; + using ostream_type = std::basic_ostream; + using test_type = decltype(make_ostream_joiner(std::declval(), + std::declval())); + + static_assert(is_same_v, ""); + + static_assert(is_same_v, ""); + + static_assert(is_same_v>, ""); + + static_assert(is_same_v, ""); + + static_assert(is_same_v, ""); + + static_assert(is_same_v, ""); + static_assert(is_same_v, ""); + static_assert(is_same_v, ""); + static_assert(is_same_v, ""); +}; + +tester cc; +tester ic; +#if _GLIBCXX_USE_WCHAR_T +tester ww; +tester iw; +#endif --Edk6HoYKP7RsK9ib--