* [patch] std::experimental::ostream_joiner
@ 2015-05-02 17:14 Jonathan Wakely
2015-05-02 17:34 ` Daniel Krügler
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2015-05-02 17:14 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 197 bytes --]
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.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 12046 bytes --]
commit d4a0512671d1a727905afe8efb2798fa630e19b5
Author: Jonathan Wakely <jwakely@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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] std::experimental::ostream_joiner
2015-05-02 17:14 [patch] std::experimental::ostream_joiner Jonathan Wakely
@ 2015-05-02 17:34 ` Daniel Krügler
2015-05-02 18:04 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Krügler @ 2015-05-02 17:34 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches List
2015-05-02 19:14 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
> 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.
Do you really want to copy the ugliness of the Standard specification
for in-class members or could this be made more readable as follows
(affects four members):
ostream_joiner<_DelimT, _CharT, _Traits>&
=>
ostream_joiner&
? [I'm asking because I have not seen this to be the general style
used in libstdc++]
- Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] std::experimental::ostream_joiner
2015-05-02 17:34 ` Daniel Krügler
@ 2015-05-02 18:04 ` Jonathan Wakely
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2015-05-02 18:04 UTC (permalink / raw)
To: Daniel Krügler; +Cc: libstdc++, gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 965 bytes --]
On 02/05/15 19:34 +0200, Daniel Krügler wrote:
>2015-05-02 19:14 GMT+02:00 Jonathan Wakely <jwakely@redhat.com>:
>> 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.
>
>Do you really want to copy the ugliness of the Standard specification
>for in-class members or could this be made more readable as follows
>(affects four members):
>
>ostream_joiner<_DelimT, _CharT, _Traits>&
>=>
>ostream_joiner&
>
>? [I'm asking because I have not seen this to be the general style
>used in libstdc++]
Good point, I should probably stop working now, I've already spent my
whole Saturday and I'm clearly not paying attention properly!
The TS should be fixed to use the injected-class-name too:
https://github.com/cplusplus/fundamentals-ts/pull/56
Fixed by this patch, tested powerpc64le-linux and committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1830 bytes --]
commit af7ef923b9b95f5c7c59e6706095fba460a23a81
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat May 2 19:00:16 2015 +0100
* include/experimental/iterator (ostream_joiner): Simplify by using
the injected-class-name and the ostream_type typedef.
diff --git a/libstdc++-v3/include/experimental/iterator b/libstdc++-v3/include/experimental/iterator
index 027043a..9a38f6b 100644
--- a/libstdc++-v3/include/experimental/iterator
+++ b/libstdc++-v3/include/experimental/iterator
@@ -80,7 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ }
template<typename _Tp>
- ostream_joiner<_DelimT, _CharT, _Traits>&
+ ostream_joiner&
operator=(const _Tp& __value)
{
if (!_M_first)
@@ -90,20 +90,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
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; }
+ ostream_joiner& operator*() noexcept { return *this; }
+ ostream_joiner& operator++() noexcept { return *this; }
+ ostream_joiner& operator++(int) noexcept { return *this; }
private:
- basic_ostream<_CharT, _Traits>* _M_out;
+ ostream_type* _M_out;
_DelimT _M_delim;
bool _M_first = true;
};
@@ -113,9 +105,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline ostream_joiner<decay_t<_DelimT>, _CharT, _Traits>
make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os,
_DelimT&& __delimiter)
- {
- return { __os, std::forward<_DelimT>(__delimiter) };
- }
+ { return { __os, std::forward<_DelimT>(__delimiter) }; }
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace fundamentals_v2
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-02 18:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-02 17:14 [patch] std::experimental::ostream_joiner Jonathan Wakely
2015-05-02 17:34 ` Daniel Krügler
2015-05-02 18:04 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).