]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/25_algorithms/inplace_merge/moveable.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / inplace_merge / moveable.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 25.3.4 [lib.alg.merge]
21
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
25 #include <testsuite_rvalref.h>
26
27 using __gnu_test::test_container;
28 using __gnu_test::bidirectional_iterator_wrapper;
29 using __gnu_test::rvalstruct;
30
31 typedef test_container<rvalstruct, bidirectional_iterator_wrapper> container;
32
33 void
34 test01()
35 {
36 int array1[]={0,2,4,1,3,5};
37 rvalstruct rv_array1[6];
38 std::copy(array1, array1 + 6, rv_array1);
39 container con1(rv_array1, rv_array1 + 6);
40 std::inplace_merge(con1.begin(), con1.it(3), con1.end());
41 VERIFY( rv_array1[0] == 0 && rv_array1[1] == 1 && rv_array1[2] == 2
42 && rv_array1[3] == 3 && rv_array1[4] == 4 && rv_array1[5] == 5 );
43
44 int array2[]={0,2,4,5,1,3};
45 rvalstruct rv_array2[6];
46 std::copy(array2, array2 + 6, rv_array2);
47 container con2(rv_array2, rv_array2 + 6);
48 std::inplace_merge(con2.begin(), con2.it(4), con2.end());
49 VERIFY( rv_array2[0] == 0 && rv_array2[1] == 1 && rv_array2[2] == 2
50 && rv_array2[3] == 3 && rv_array2[4] == 4 && rv_array2[5] == 5 );
51
52 int array3[]={1,1,1,2,2,2};
53 rvalstruct rv_array3[6];
54 std::copy(array3, array3 + 6, rv_array3);
55 container con3(rv_array3, rv_array3 + 6);
56 std::inplace_merge(con3.begin(), con3.it(3), con3.end());
57 VERIFY( rv_array3[0] == 1 && rv_array3[1] == 1 && rv_array3[2] == 1
58 && rv_array3[3] == 2 && rv_array3[4] == 2 && rv_array3[5] == 2 );
59
60 int array4[]={1,1,1,1,2,2};
61 rvalstruct rv_array4[6];
62 std::copy(array4, array4 + 6, rv_array4);
63 container con4(rv_array4, rv_array4 + 6);
64 std::inplace_merge(con4.begin(), con4.it(4), con4.end());
65 VERIFY( rv_array4[0] == 1 && rv_array4[1] == 1 && rv_array4[2] == 1
66 && rv_array4[3] == 1 && rv_array4[4] == 2 && rv_array4[5] == 2 );
67
68 int array5[]={3,3,3,3};
69 rvalstruct rv_array5[4];
70 std::copy(array5, array5 + 4, rv_array5);
71 container con5(rv_array5, rv_array5 + 4);
72 std::inplace_merge(con5.begin(), con5.it(2), con5.end());
73 VERIFY( rv_array5[0] == 3 && rv_array5[1] == 3 && rv_array5[2] == 3
74 && rv_array5[3] == 3 );
75
76 int array6[]={3,3,3};
77 rvalstruct rv_array6[3];
78 std::copy(array6, array6 + 3, rv_array6);
79 container con6(rv_array6, rv_array6 + 3);
80 std::inplace_merge(con6.begin(), con6.it(0), con6.end());
81 VERIFY( rv_array6[0] == 3 && rv_array6[1] == 3 && rv_array6[2] == 3 );
82
83 int array7[]={3,3};
84 rvalstruct rv_array7[2];
85 std::copy(array7, array7 + 2, rv_array7);
86 container con7(rv_array7, rv_array7 + 2);
87 std::inplace_merge(con7.begin(), con7.it(2), con7.end());
88 VERIFY( rv_array7[0] == 3 && rv_array7[1] == 3 );
89 }
90
91 int
92 main()
93 {
94 test01();
95 return 0;
96 }