]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/any/assign/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / any / assign / 2.cc
CommitLineData
52066eae 1// { dg-do run { target c++14 } }
e8043fa6 2
7adcbafe 3// Copyright (C) 2014-2022 Free Software Foundation, Inc.
e8043fa6
JW
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#include <experimental/any>
21#include <testsuite_hooks.h>
22
23using std::experimental::any;
24using std::experimental::any_cast;
25
a3f6007c
VV
26bool moved = false;
27bool copied = false;
28
29
e8043fa6
JW
30struct X
31{
e8043fa6 32 X() = default;
a3f6007c 33 X(const X&) { copied = true; }
13feb023 34 X(X&&) { moved = true; }
a3f6007c
VV
35};
36
37struct X2
38{
39 X2() = default;
40 X2(const X2&) { copied = true; }
13feb023 41 X2(X2&&) noexcept { moved = true; }
e8043fa6
JW
42};
43
44void test01()
45{
a3f6007c 46 moved = false;
e8043fa6
JW
47 X x;
48 any a1;
49 a1 = x;
a3f6007c 50 VERIFY(moved == false);
e8043fa6 51 any a2;
a3f6007c 52 copied = false;
e8043fa6 53 a2 = std::move(x);
a3f6007c
VV
54 VERIFY(moved == true);
55 VERIFY(copied == false);
e8043fa6
JW
56}
57
a3f6007c
VV
58void test02()
59{
60 moved = false;
61 X x;
62 any a1;
63 a1 = x;
64 VERIFY(moved == false);
65 any a2;
66 copied = false;
67 a2 = std::move(a1);
68 VERIFY(moved == false);
69 VERIFY(copied == false);
70}
71
72void test03()
73{
74 moved = false;
75 X2 x;
76 any a1;
77 a1 = x;
78 VERIFY(copied && moved);
79 any a2;
80 moved = false;
81 copied = false;
82 a2 = std::move(a1);
83 VERIFY(moved == true);
84 VERIFY(copied == false);
85 }
86
e8043fa6
JW
87int main()
88{
89 test01();
a3f6007c
VV
90 test02();
91 test03();
e8043fa6 92}