xref: /llvm-project/libcxx/test/std/utilities/any/any.nonmembers/swap.pass.cpp (revision ec350ad418a24f70c88758259c774a1e11c06d74)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 
11 // <any>
12 
13 // void swap(any &, any &) noexcept
14 
15 // swap(...) just wraps any::swap(...). That function is tested elsewhere.
16 
17 #include <any>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24 
25     { // test noexcept
26         std::any a;
27         static_assert(noexcept(swap(a, a)), "swap(any&, any&) must be noexcept");
28     }
29     {
30         std::any a1 = 1;
31         std::any a2 = 2;
32 
33         swap(a1, a2);
34 
35         assert(std::any_cast<int>(a1) == 2);
36         assert(std::any_cast<int>(a2) == 1);
37     }
38 
39   return 0;
40 }
41