OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [nth_element/] [moveable.cc] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// { 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.2 [lib.alg.nth.element]
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
 
34
using __gnu_test::test_container;
35
using __gnu_test::random_access_iterator_wrapper;
36
using std::nth_element;
37
using __gnu_test::rvalstruct;
38
 
39
typedef test_container<rvalstruct, random_access_iterator_wrapper> Container;
40
 
41
void
42
test1()
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
  nth_element(con.begin(), con.it(3), con.end());
51
  for(int i = 0; i < 3; ++i)
52
    VERIFY( array[i].val < 3 );
53
  for(int i = 4; i < 7; ++i)
54
    VERIFY( array[i].val > 3 );
55
  for(int i = 0; i < 7; ++i)
56
    VERIFY( array[i].valid );
57
}
58
 
59
void
60
test2()
61
{
62
  bool test __attribute__((unused)) = true;
63
 
64
  int intarray[] = {0, 6, 1, 5, 2, 4, 3};
65
  rvalstruct array[7];
66
  std::copy(intarray, intarray + 7, array);
67
  Container con(array,array + 7);
68
  nth_element(con.begin(), con.it(3), con.end());
69
  for(int i = 0; i < 3; ++i)
70
    VERIFY( array[i].val < 3 );
71
  for(int i = 4; i < 7; ++i)
72
    VERIFY( array[i].val > 3 );
73
  for(int i = 0; i < 7; ++i)
74
    VERIFY( array[i].valid );
75
}
76
 
77
bool
78
are_less(const rvalstruct& lhs, const rvalstruct& rhs)
79
{ return lhs < rhs; }
80
 
81
void
82
test3()
83
{
84
  bool test __attribute__((unused)) = true;
85
 
86
  int intarray[] = {0, 6, 1, 5, 2, 4, 3};
87
  rvalstruct array[7];
88
  std::copy(intarray, intarray + 7, array);
89
  Container con(array,array + 7);
90
  nth_element(con.begin(), con.it(3), con.end(), are_less);
91
  for(int i = 0; i < 3; ++i)
92
    VERIFY( array[i].val < 3 );
93
  for(int i = 4; i < 7; ++i)
94
    VERIFY( array[i].val > 3 );
95
  for(int i = 0; i < 7; ++i)
96
    VERIFY( array[i].valid );
97
}
98
 
99
int
100
main()
101
{
102
  test1();
103
  test2();
104
  test3();
105
  return 0;
106
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.