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