From a623b6f0116e4d8ad004fcdc665c2395eddc6953 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Sat, 2 May 2015 18:14:25 +0100 Subject: [PATCH] iterator: New. * 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. From-SVN: r222727 --- libstdc++-v3/ChangeLog | 9 ++ libstdc++-v3/doc/html/manual/status.html | 8 +- .../doc/xml/manual/status_cxx2017.xml | 7 +- libstdc++-v3/include/Makefile.am | 1 + libstdc++-v3/include/Makefile.in | 1 + libstdc++-v3/include/experimental/iterator | 127 ++++++++++++++++++ .../iterator/make_ostream_joiner.cc | 38 ++++++ .../experimental/iterator/ostream_joiner.cc | 73 ++++++++++ .../experimental/iterator/requirements.cc | 58 ++++++++ 9 files changed, 314 insertions(+), 8 deletions(-) create mode 100644 libstdc++-v3/include/experimental/iterator create mode 100644 libstdc++-v3/testsuite/experimental/iterator/make_ostream_joiner.cc create mode 100644 libstdc++-v3/testsuite/experimental/iterator/ostream_joiner.cc create mode 100644 libstdc++-v3/testsuite/experimental/iterator/requirements.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9d790b20771..4f5fa683e2d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2015-05-02 Jonathan Wakely + * 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. + * include/experimental/numeric: New. Define gcd and lcm. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. diff --git a/libstdc++-v3/doc/html/manual/status.html b/libstdc++-v3/doc/html/manual/status.html index 413deae6d74..2fd0d6e99ae 100644 --- a/libstdc++-v3/doc/html/manual/status.html +++ b/libstdc++-v3/doc/html/manual/status.html @@ -520,11 +520,11 @@ not in any particular release. N4061 - Greatest Common Divisor and Least Common MultipleYLibrary Fundamentals 2 TS - - N4257 + Greatest Common Divisor and Least Common MultipleYLibrary Fundamentals 2 TS + + N4066 - Delimited iteratorsNLibrary Fundamentals 2 TS + Delimited iteratorsYLibrary Fundamentals 2 TS N4282 diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index c30bf09cdf4..ee32a2befd8 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 92b386a1adb..06a4805ae57 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/Makefile.in b/libstdc++-v3/include/Makefile.in index 4a721a296c8..19e4b8e2697 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -918,6 +918,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 00000000000..027043a9a45 --- /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 00000000000..76d3a974f45 --- /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 00000000000..c78dbe66d87 --- /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 00000000000..54a7f8e95df --- /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 -- 2.30.2