| 1 | // { dg-do run { target c++11 } } |
| 2 | // Copyright (C) 2019-2025 Free Software Foundation, Inc. |
| 3 | // |
| 4 | // This file is part of the GNU ISO C++ Library. This library is free |
| 5 | // software; you can redistribute it and/or modify it under the |
| 6 | // terms of the GNU General Public License as published by the |
| 7 | // Free Software Foundation; either version 3, or (at your option) |
| 8 | // any later version. |
| 9 | |
| 10 | // This library is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | |
| 15 | // You should have received a copy of the GNU General Public License along |
| 16 | // with this library; see the file COPYING3. If not see |
| 17 | // <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | #include <algorithm> |
| 20 | #include <vector> |
| 21 | #include <list> |
| 22 | #include <deque> |
| 23 | |
| 24 | #include <testsuite_hooks.h> |
| 25 | |
| 26 | void test01() |
| 27 | { |
| 28 | using namespace std; |
| 29 | |
| 30 | deque<int> d; |
| 31 | for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i) |
| 32 | d.push_back(i); |
| 33 | |
| 34 | deque<int> dest(d.size(), 0); |
| 35 | |
| 36 | move(d.begin(), d.end(), dest.begin()); |
| 37 | |
| 38 | VERIFY( equal(dest.begin(), dest.end(), d.begin()) ); |
| 39 | } |
| 40 | |
| 41 | void test02() |
| 42 | { |
| 43 | using namespace std; |
| 44 | |
| 45 | deque<int> d; |
| 46 | for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i) |
| 47 | d.push_back(i); |
| 48 | |
| 49 | deque<int> dest(d.size(), 0); |
| 50 | |
| 51 | const deque<int>& cd = d; |
| 52 | move(cd.begin(), cd.end(), dest.begin()); |
| 53 | |
| 54 | VERIFY( equal(dest.begin(), dest.end(), cd.begin()) ); |
| 55 | } |
| 56 | |
| 57 | void test03() |
| 58 | { |
| 59 | std::deque<int> d; |
| 60 | for (int i = 0; i != 1024; ++i) |
| 61 | d.push_back(i); |
| 62 | |
| 63 | std::vector<int> dest(d.size(), 0); |
| 64 | |
| 65 | std::move(d.begin(), d.end(), dest.begin()); |
| 66 | VERIFY( std::equal(dest.begin(), dest.end(), d.begin()) ); |
| 67 | } |
| 68 | |
| 69 | void test04() |
| 70 | { |
| 71 | std::vector<int> v; |
| 72 | for (int i = 0; i != 1024; ++i) |
| 73 | v.push_back(i); |
| 74 | |
| 75 | std::deque<int> dest(v.size() - 10, 0); |
| 76 | |
| 77 | std::move(v.begin() + 5, v.end() - 5, dest.begin()); |
| 78 | VERIFY( std::equal(dest.begin(), dest.end(), v.begin() + 5) ); |
| 79 | } |
| 80 | |
| 81 | void test05() |
| 82 | { |
| 83 | std::list<int> l; |
| 84 | for (int i = 0; i != 1024; ++i) |
| 85 | l.push_back(i); |
| 86 | |
| 87 | std::deque<int> dest(l.size(), 0); |
| 88 | |
| 89 | std::move(l.begin(), l.end(), dest.begin()); |
| 90 | VERIFY( std::equal(dest.begin(), dest.end(), l.begin()) ); |
| 91 | } |
| 92 | |
| 93 | int main() |
| 94 | { |
| 95 | test01(); |
| 96 | test02(); |
| 97 | test03(); |
| 98 | test04(); |
| 99 | test05(); |
| 100 | return 0; |
| 101 | } |