1 // { dg-do run { target c++11 } }
2 
3 // Copyright (C) 2009-2018 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 bool
are_ordered(const rvalstruct & lhs,const rvalstruct & rhs)34 are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
35 { return lhs < rhs; }
36 
37 void
test01()38 test01()
39 {
40   int array1[]={0,2,4,1,3,5};
41   rvalstruct rv_array1[6];
42   std::copy(array1, array1 + 6, rv_array1);
43   container con1(rv_array1, rv_array1 + 6);
44   std::inplace_merge(con1.begin(), con1.it(3), con1.end(), are_ordered);
45   VERIFY( rv_array1[0] == 0 && rv_array1[1] == 1 && rv_array1[2] == 2
46 	  && rv_array1[3] == 3 && rv_array1[4] == 4 && rv_array1[5] == 5 );
47 
48   int array2[]={0,2,4,5,1,3};
49   rvalstruct rv_array2[6];
50   std::copy(array2, array2 + 6, rv_array2);
51   container con2(rv_array2, rv_array2 + 6);
52   std::inplace_merge(con2.begin(), con2.it(4), con2.end(), are_ordered);
53   VERIFY( rv_array2[0] == 0 && rv_array2[1] == 1 && rv_array2[2] == 2
54 	  && rv_array2[3] == 3 && rv_array2[4] == 4 && rv_array2[5] == 5 );
55 
56   int array3[]={1,1,1,2,2,2};
57   rvalstruct rv_array3[6];
58   std::copy(array3, array3 + 6, rv_array3);
59   container con3(rv_array3, rv_array3 + 6);
60   std::inplace_merge(con3.begin(), con3.it(3), con3.end(), are_ordered);
61   VERIFY( rv_array3[0] == 1 && rv_array3[1] == 1 && rv_array3[2] == 1
62 	  && rv_array3[3] == 2 && rv_array3[4] == 2 && rv_array3[5] == 2 );
63 
64   int array4[]={1,1,1,1,2,2};
65   rvalstruct rv_array4[6];
66   std::copy(array4, array4 + 6, rv_array4);
67   container con4(rv_array4, rv_array4 + 6);
68   std::inplace_merge(con4.begin(), con4.it(4), con4.end(), are_ordered);
69   VERIFY( rv_array4[0] == 1 && rv_array4[1] == 1 && rv_array4[2] == 1
70 	  && rv_array4[3] == 1 && rv_array4[4] == 2 && rv_array4[5] == 2 );
71 
72   int array5[]={3,3,3,3};
73   rvalstruct rv_array5[4];
74   std::copy(array5, array5 + 4, rv_array5);
75   container con5(rv_array5, rv_array5 + 4);
76   std::inplace_merge(con5.begin(), con5.it(2), con5.end(), are_ordered);
77   VERIFY( rv_array5[0] == 3 && rv_array5[1] == 3 && rv_array5[2] == 3
78 	  && rv_array5[3] == 3 );
79 
80   int array6[]={3,3,3};
81   rvalstruct rv_array6[3];
82   std::copy(array6, array6 + 3, rv_array6);
83   container con6(rv_array6, rv_array6 + 3);
84   std::inplace_merge(con6.begin(), con6.it(0), con6.end(), are_ordered);
85   VERIFY( rv_array6[0] == 3 && rv_array6[1] == 3 && rv_array6[2] == 3 );
86 
87   int array7[]={3,3};
88   rvalstruct rv_array7[2];
89   std::copy(array7, array7 + 2, rv_array7);
90   container con7(rv_array7, rv_array7 + 2);
91   std::inplace_merge(con7.begin(), con7.it(2), con7.end(), are_ordered);
92   VERIFY( rv_array7[0] == 3 && rv_array7[1] == 3 );
93 }
94 
95 int
main()96 main()
97 {
98   test01();
99   return 0;
100 }
101