From 4e05c918d28e3fa66f5baaf556f6886447c68c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dumont?= Date: Wed, 22 Jan 2020 18:21:28 +0100 Subject: libstdc++: Specialize copy/copy_n for istreambuf_iterator and deque iterators Add __copy_n_a overloads for std::deque iterators to replace with C memmove when possible. Expose std::copy_n implementation details in pre-C++11 modes and use it for std::copy overloads. libstdc++-v3/ChangeLog * include/bits/stl_algo.h (__copy_n_a): Move to ... * include/bits/stl_algobase.h (__copy_n_a): ...here. Add __strict parameter. (__copy_n_a(istreambuf_iterator<>, _Size, _Deque_iterator<>, bool)): Declare. (__niter_base(const _Safe_iterator<_Ite, _Seq, random_access_iterator_tag>&)): Declare. (__copy_move_a2(istreambuf_iterator<>, istreambuf_iterator<>, _Deque_iterator<>)): Declare. * include/bits/deque.tcc (__copy_move_a2(istreambuf_iterator<>, istreambuf_iterator<>, _Deque_iterator<>)): New. (__copy_n_a(istreambuf_iterator<>, _Size, _Deque_iterator<>, bool)): New. * include/bits/streambuf_iterator.h (__copy_n_a(istreambuf_iterator<>, _Size, _CharT*, bool)): Adapt. * include/debug/safe_iterator.tcc (__niter_base): New. * testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc (test03): New. * testsuite/25_algorithms/copy/streambuf_iterators/char/debug/deque_neg.cc: New test. * testsuite/25_algorithms/copy_n/debug/istreambuf_ite_deque_neg.cc: New test. * testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc: New test. * testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc: New test. --- .../copy/streambuf_iterators/char/4.cc | 26 ++++++++++ .../streambuf_iterators/char/debug/deque_neg.cc | 46 ++++++++++++++++++ .../copy_n/debug/istreambuf_ite_deque_neg.cc | 50 +++++++++++++++++++ .../25_algorithms/copy_n/istreambuf_iterator/2.cc | 56 ++++++++++++++++++++++ .../copy_n/istreambuf_iterator/deque.cc | 56 ++++++++++++++++++++++ 5 files changed, 234 insertions(+) create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/debug/deque_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy_n/debug/istreambuf_ite_deque_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc (limited to 'libstdc++-v3/testsuite/25_algorithms') diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc index fe04e9342e7..bc23497ff0e 100644 --- a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -76,9 +77,34 @@ void test02() VERIFY( !memcmp(buffer.data(), buffer_ref, 16500) ); } +void test03() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + ifstream fbuf_ref("istream_unformatted-1.txt"), + fbuf("istream_unformatted-1.txt"); + + char buffer_ref[16500]; + std::deque buffer(16500, 'a'); + + fbuf_ref.read(buffer_ref, 16500); + + in_iterator_type beg(fbuf); + in_iterator_type end; + copy(beg, end, buffer.begin()); + + VERIFY( fbuf_ref.good() ); + VERIFY( fbuf.good() ); + + VERIFY( std::equal(buffer.begin(), buffer.end(), buffer_ref) ); +} + int main() { test01(); test02(); + test03(); return 0; } diff --git a/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/debug/deque_neg.cc b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/debug/deque_neg.cc new file mode 100644 index 00000000000..26627e37440 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy/streambuf_iterators/char/debug/deque_neg.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2020 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-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + const char data1[] = "Drei Phantasien nach Friedrich Holderlin"; + const string str1(data1); + istringstream iss1(str1); + in_iterator_type beg1(iss1); + in_iterator_type end1; + deque d(sizeof(data1) - 2, '0'); + + copy(beg1, end1, d.begin()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_n/debug/istreambuf_ite_deque_neg.cc b/libstdc++-v3/testsuite/25_algorithms/copy_n/debug/istreambuf_ite_deque_neg.cc new file mode 100644 index 00000000000..ede641820b5 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/debug/istreambuf_ite_deque_neg.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2020 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-do run { target c++11 xfail *-*-* } } +// { dg-require-fileio "" } +// { dg-require-debug-mode "" } + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + ifstream fbuf_ref("istream_unformatted-1.txt"), + fbuf("istream_unformatted-1.txt"); + + char buffer_ref[16500]; + deque dq(17000, 'a'); + + fbuf_ref.read(buffer_ref, 16500); + + in_iterator_type beg(fbuf); + copy_n(beg, 17000, dq.begin()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc new file mode 100644 index 00000000000..5e1a0c2b75b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc @@ -0,0 +1,56 @@ +// { dg-do run { target c++11 } } +// { dg-require-fileio "" } + +// Copyright (C) 2020 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 +// . + +#include +#include +#include +#include + +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + ifstream fbuf_ref("istream_unformatted-1.txt"), + fbuf("istream_unformatted-1.txt"); + + char buffer_ref[16500], + buffer[16501]; + + fbuf_ref.read(buffer_ref, 16500); + + in_iterator_type beg(fbuf); + copy_n(beg, 16500, buffer); + + VERIFY( fbuf_ref.good() ); + VERIFY( fbuf.good() ); + + VERIFY( !memcmp(buffer, buffer_ref, 16500) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc new file mode 100644 index 00000000000..ace73701b90 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc @@ -0,0 +1,56 @@ +// { dg-do run { target c++11 } } +// { dg-require-fileio "" } + +// Copyright (C) 2020 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 +// . + +#include +#include +#include +#include + +#include + +void test01() +{ + using namespace std; + + typedef istreambuf_iterator in_iterator_type; + + ifstream fbuf_ref("istream_unformatted-1.txt"), + fbuf("istream_unformatted-1.txt"); + + char buffer_ref[16500]; + deque dq(16500, 'a'); + + fbuf_ref.read(buffer_ref, 16500); + + in_iterator_type beg(fbuf); + copy_n(beg, 16500, dq.begin()); + + VERIFY( fbuf_ref.good() ); + VERIFY( fbuf.good() ); + + VERIFY( equal(dq.begin(), dq.end(), buffer_ref) ); +} + +int +main() +{ + test01(); + return 0; +} -- cgit v1.2.3