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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [20_util/] [tuple/] [swap.cc] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// { dg-options "-std=gnu++0x" }
2
 
3
// Copyright (C) 2007, 2009 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
 
21
// NOTE: This makes use of the fact that we know how moveable
22
// is implemented on tuple.  If the implementation changed
23
// this test may begin to fail.
24
 
25
#include <tuple>
26
#include <utility>
27
#include <testsuite_hooks.h>
28
 
29
struct MoveOnly
30
{
31
  explicit MoveOnly (int j) : i(j) { }
32
 
33
  MoveOnly (MoveOnly&& m) : i(m.i) { }
34
 
35
  MoveOnly& operator=(MoveOnly&& m)
36
  { i = m.i; return *this; }
37
 
38
  MoveOnly(MoveOnly const&) = delete;
39
  MoveOnly& operator=(MoveOnly const&) = delete;
40
 
41
  bool operator==(MoveOnly const& m)
42
  { return i == m.i; }
43
 
44
  void swap(MoveOnly& m)
45
  { std::swap(m.i, i); }
46
 
47
  int i;
48
};
49
 
50
void swap(MoveOnly& m1, MoveOnly& m2)
51
{ m1.swap(m2); }
52
 
53
MoveOnly
54
make_move_only (int i)
55
{ return MoveOnly(i); }
56
 
57
void test01()
58
{
59
  bool test __attribute__((unused)) = true;
60
 
61
  std::tuple<> t1, t2;
62
  std::swap(t1, t2);
63
 
64
  VERIFY( t1 == t2 );
65
}
66
 
67
void test02()
68
{
69
  bool test __attribute__((unused)) = true;
70
 
71
  std::tuple<int> t1(1), t2(2);
72
  std::swap(t1, t2);
73
 
74
  VERIFY( std::get<0>(t1) == 2 && std::get<0>(t2) == 1 );
75
}
76
 
77
void test03()
78
{
79
  bool test __attribute__((unused)) = true;
80
 
81
  std::tuple<int, float> t1(1, 1.0f), t2(2, 2.0f);
82
  std::swap(t1, t2);
83
 
84
  VERIFY( std::get<0>(t1) == 2 && std::get<0>(t2) == 1 );
85
  VERIFY( std::get<1>(t1) == 2.0f && std::get<1>(t2) == 1.0f );
86
}
87
 
88
void test04()
89
{
90
  bool test __attribute__((unused)) = true;
91
 
92
  std::tuple<int, float, MoveOnly>
93
    t1(1, 1.0f, make_move_only(1)),
94
    t2(2, 2.0f, make_move_only(2));
95
 
96
  std::swap(t1, t2);
97
 
98
  VERIFY( std::get<0>(t1) == 2 && std::get<0>(t2) == 1 );
99
  VERIFY( std::get<1>(t1) == 2.0f && std::get<1>(t2) == 1.0f );
100
  VERIFY( std::get<2>(t1) == make_move_only(2)
101
          && std::get<2>(t2) == make_move_only(1) );
102
}
103
 
104
int main()
105
{
106
  test01();
107
  test02();
108
  test03();
109
  test04();
110
  return 0;
111
}

powered by: WebSVN 2.1.0

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