]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/forward_list/operations/6.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / forward_list / operations / 6.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
3a63c9cd 2
8d9254fc 3// Copyright (C) 2008-2020 Free Software Foundation, Inc.
3a63c9cd
ESR
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
3a63c9cd
ESR
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
2328b1de 12// but WITHOUT ANY WARRANTY; without even the implied warranty of
3a63c9cd
ESR
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
3a63c9cd
ESR
19
20// 23.2.3.n forward_list xxx [lib.forward_list.xxx]
21
22#include <forward_list>
23#include <testsuite_hooks.h>
24
3a63c9cd
ESR
25// Comparison functor.
26template<typename Num>
27 class Comp
28 {
29 public:
30 Comp(const Num & num)
31 {
32 n = num;
33 }
34 bool operator()(const Num i, const Num j)
35 {
36 return (n * i) < (n * j);
37 }
38 private:
39 Num n;
40 };
41
42// This test verifies the following:
43//
44void
45test01()
46{
47 const unsigned int n = 13;
48 int order[][n] = {
49 { 0,1,2,3,4,5,6,7,8,9,10,11,12 },
50 { 6,2,8,4,11,1,12,7,3,9,5,0,10 },
51 { 12,11,10,9,8,7,6,5,4,3,2,1,0 },
52 };
53 std::forward_list<int> sorted(order[0], order[0] + n);
54
55 for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i)
56 {
57 std::forward_list<int> head(order[i], order[i] + n);
58
59 head.sort();
60
61 VERIFY(head == sorted);
62 }
63
64 std::forward_list<int> reversed(order[2], order[2] + n);
65 for (unsigned int i = 0; i < sizeof(order)/sizeof(*order); ++i)
66 {
67 std::forward_list<int> head(order[i], order[i] + n);
68
69 Comp<int> comp(-1);
70 head.sort( comp );
71
72 VERIFY(head == reversed);
73 }
74}
75
76int
77main()
78{
79 test01();
80 return 0;
81}