| 1 | // Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // 25.2.1 [lib.alg.copy] Copy. |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | class Counting_output_iterator |
| 24 | : public std::iterator< std::output_iterator_tag, void, void, void, void > // { dg-warning "is deprecated" "" { target c++17 } } |
| 25 | { |
| 26 | std::size_t c; |
| 27 | public: |
| 28 | Counting_output_iterator() : c(0) {} |
| 29 | Counting_output_iterator& operator++() { return *this; } |
| 30 | Counting_output_iterator operator++(int) { return *this; } |
| 31 | Counting_output_iterator& operator*() { return *this; } |
| 32 | |
| 33 | template <typename T> |
| 34 | void operator=(const T&) { ++c; } |
| 35 | |
| 36 | std::size_t current_counter() const { return c; } |
| 37 | }; |
| 38 | |
| 39 | // libstdc++/34595 |
| 40 | void test01() |
| 41 | { |
| 42 | int t[10] = {0,}; |
| 43 | Counting_output_iterator cnt; |
| 44 | std::size_t res = std::copy(t+0, t+5, cnt).current_counter(); |
| 45 | |
| 46 | VERIFY( res == 5 ); |
| 47 | } |
| 48 | |
| 49 | int main() |
| 50 | { |
| 51 | test01(); |
| 52 | return 0; |
| 53 | } |