mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-19 00:01:21 +08:00
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
This commit is contained in:
parent
3435c26f32
commit
a623b6f011
@ -1,5 +1,14 @@
|
||||
2015-05-02 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
* 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.
|
||||
|
@ -520,11 +520,11 @@ not in any particular release.
|
||||
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4061.pdf" target="_top">
|
||||
N4061
|
||||
</a>
|
||||
</td><td align="left">Greatest Common Divisor and Least Common Multiple</td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr bgcolor="#C8B0B0"><td align="left">
|
||||
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4257.html" target="_top">
|
||||
N4257
|
||||
</td><td align="left">Greatest Common Divisor and Least Common Multiple</td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr><td align="left">
|
||||
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4066.htm" target="_top">
|
||||
N4066
|
||||
</a>
|
||||
</td><td align="left">Delimited iterators</td><td align="left">N</td><td align="left">Library Fundamentals 2 TS</td></tr><tr><td align="left">
|
||||
</td><td align="left">Delimited iterators</td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr><td align="left">
|
||||
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4282.pdf" target="_top">
|
||||
N4282
|
||||
</a>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
127
libstdc++-v3/include/experimental/iterator
Normal file
127
libstdc++-v3/include/experimental/iterator
Normal file
@ -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
|
@ -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();
|
||||
}
|
@ -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();
|
||||
}
|
58
libstdc++-v3/testsuite/experimental/iterator/requirements.cc
Normal file
58
libstdc++-v3/testsuite/experimental/iterator/requirements.cc
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user