1// { dg-options "-std=gnu++0x" } 2 3// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 4// Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// You should have received a copy of the GNU General Public License along 18// with this library; see the file COPYING3. If not see 19// <http://www.gnu.org/licenses/>. 20 21// 25.3.1.3 [lib.partial.sort] 22 23#undef _GLIBCXX_CONCEPT_CHECKS 24 25// XXX FIXME: parallel-mode should deal correctly with moveable-only types 26// per C++0x, at minimum smoothly fall back to serial. 27#undef _GLIBCXX_PARALLEL 28 29#include <algorithm> 30#include <testsuite_hooks.h> 31#include <testsuite_iterators.h> 32#include <testsuite_rvalref.h> 33 34using __gnu_test::test_container; 35using __gnu_test::random_access_iterator_wrapper; 36using __gnu_test::rvalstruct; 37using std::partial_sort; 38 39typedef test_container<rvalstruct, random_access_iterator_wrapper> Container; 40 41void 42test1() 43{ 44 bool test __attribute__((unused)) = true; 45 46 int intarray[] = {6, 5, 4, 3, 2, 1, 0}; 47 rvalstruct array[7]; 48 std::copy(intarray, intarray + 7, array); 49 Container con(array, array + 7); 50 partial_sort(con.begin(), con.it(3), con.end()); 51 VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 ); 52 for(int i = 0; i < 7; ++i) 53 VERIFY( array[i].valid ); 54} 55 56void 57test2() 58{ 59 bool test __attribute__((unused)) = true; 60 61 int intarray[] = {0, 6, 1, 5, 2, 4, 3}; 62 rvalstruct array[7]; 63 std::copy(intarray, intarray + 7, array); 64 Container con(array,array + 7); 65 partial_sort(con.begin(), con.it(3), con.end()); 66 VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 ); 67 for(int i = 0; i < 7; ++i) 68 VERIFY( array[i].valid ); 69} 70 71bool are_less(const rvalstruct& lhs, const rvalstruct& rhs) 72{ return lhs < rhs; } 73 74void 75test3() 76{ 77 bool test __attribute__((unused)) = true; 78 79 int intarray[] = {0, 6, 1, 5, 2, 4, 3}; 80 rvalstruct array[7]; 81 std::copy(intarray, intarray + 7, array); 82 Container con(array,array + 7); 83 partial_sort(con.begin(), con.it(3), con.end(), are_less); 84 VERIFY( array[0].val == 0 && array[1].val == 1 && array[2].val == 2 ); 85 for(int i = 0; i < 7; ++i) 86 VERIFY( array[i].valid ); 87} 88 89int 90main() 91{ 92 test1(); 93 test2(); 94 test3(); 95 return 0; 96} 97