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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [partition/] [moveable.cc] - Blame information for rev 424

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 Pred 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.2.12 [lib.alg.partitions] Partitions.
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 <functional>
31
#include <testsuite_hooks.h>
32
#include <testsuite_rvalref.h>
33
#include <testsuite_iterators.h>
34
 
35
using __gnu_test::test_container;
36
using __gnu_test::forward_iterator_wrapper;
37
using __gnu_test::bidirectional_iterator_wrapper;
38
using __gnu_test::rvalstruct;
39
 
40
typedef test_container<rvalstruct, forward_iterator_wrapper> Fcontainer;
41
typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Bcontainer;
42
 
43
bool test __attribute__((unused)) = true;
44
 
45
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
46
const int B[] = {2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 17};
47
const int N = sizeof(A) / sizeof(int);
48
 
49
struct Pred
50
{
51
    bool
52
    operator()(const rvalstruct& x) const
53
    { return (x.val % 2) == 0; }
54
};
55
 
56
// 25.2.12 partition()
57
void
58
test01()
59
{
60
  using std::partition;
61
 
62
  rvalstruct farray[N];
63
  rvalstruct barray[N];
64
 
65
  std::copy(A, A + N, farray);
66
  std::copy(A, A + N, barray);
67
 
68
  Fcontainer fcon(farray, farray + N);
69
  Bcontainer bcon(barray, barray + N);
70
 
71
  Pred pred;
72
 
73
  VERIFY(partition(fcon.begin(), fcon.end(), pred).ptr - farray == N/2);
74
  for (const rvalstruct* i = farray; i < farray+N/2; ++i)
75
    VERIFY(pred(*i));
76
 
77
  for (const rvalstruct* i = farray+N/2; i < farray + N; ++i)
78
    VERIFY(!pred(*i));
79
 
80
  VERIFY(partition(bcon.begin(), bcon.end(), pred).ptr - barray == N/2);
81
 
82
  for (const rvalstruct* i = barray; i < barray+N/2; ++i)
83
    VERIFY(pred(*i));
84
  for (const rvalstruct* i = barray+N/2; i < barray + N; ++i)
85
    VERIFY(!pred(*i));
86
}
87
 
88
int
89
main()
90
{
91
  test01();
92
  return 0;
93
}

powered by: WebSVN 2.1.0

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