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.
commit d4a0512671d1a727905afe8efb2798fa630e19b5 Author: Jonathan Wakely <jwak...@redhat.com> 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. </row> <row> - <?dbhtml bgcolor="#C8B0B0" ?> <entry> - <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4257.html"> - N4257 + <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4066.htm"> + N4066 </link> </entry> <entry>Delimited iterators</entry> - <entry>N</entry> + <entry>Y</entry> <entry>Library Fundamentals 2 TS</entry> </row> 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 @@ +// <experimental/iterator> -*- 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 +// <http://www.gnu.org/licenses/>. + +/** @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 <bits/c++14_warning.h> +#else + +#include <experimental/type_traits> +#include <iosfwd> +#include <bits/move.h> +#include <bits/stl_iterator_base_types.h> + +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<typename _DelimT, typename _CharT = char, + typename _Traits = char_traits<_CharT>> + 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<typename _Tp> + 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<typename _CharT, typename _Traits, typename _DelimT> + inline ostream_joiner<decay_t<_DelimT>, _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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++14" } + +#include <experimental/iterator> +#include <sstream> +#include <testsuite_hooks.h> + +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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++14" } + +#include <experimental/iterator> +#include <sstream> +#include <testsuite_hooks.h> + +#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<int> joiner{os, 9}; + for (int i : { 1, 2, 3, 4, 5 }) + *joiner++ = i; + VERIFY( os.str() == "192939495" ); +} + +void +test02() +{ + std::ostringstream os; + ostream_joiner<char> 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<wchar_t, wchar_t> 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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// This is a compile-only test with minimal includes +#include <experimental/iterator> +#include <iosfwd> + +using namespace std::experimental; + +template<typename Delim, typename Char> +struct tester +{ + using joiner_type = ostream_joiner<Delim, Char>; + using ostream_type = std::basic_ostream<Char>; + using test_type = decltype(make_ostream_joiner(std::declval<ostream_type&>(), + std::declval<Delim>())); + + static_assert(is_same_v<test_type, joiner_type>, ""); + + static_assert(is_same_v<typename test_type::char_type, Char>, ""); + + static_assert(is_same_v<typename test_type::traits_type, + std::char_traits<Char>>, ""); + + static_assert(is_same_v<typename test_type::ostream_type, ostream_type>, ""); + + static_assert(is_same_v<typename test_type::iterator_category, + std::output_iterator_tag>, ""); + + static_assert(is_same_v<typename test_type::value_type, void>, ""); + static_assert(is_same_v<typename test_type::difference_type, void>, ""); + static_assert(is_same_v<typename test_type::pointer, void>, ""); + static_assert(is_same_v<typename test_type::reference, void>, ""); +}; + +tester<char, char> cc; +tester<int, char> ic; +#if _GLIBCXX_USE_WCHAR_T +tester<wchar_t, wchar_t> ww; +tester<int, wchar_t> iw; +#endif