Eric Fiselier | 324506b | 2016-08-11 03:13:11 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Eric Fiselier | 324506b | 2016-08-11 03:13:11 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++98, c++03, c++11, c++14 |
| 10 | |
Louis Dionne | f5f2f77 | 2019-02-05 20:11:58 +0000 | [diff] [blame] | 11 | // XFAIL: dylib-has-no-bad_any_cast && !libcpp-no-exceptions |
Mehdi Amini | e9c66ad | 2017-05-04 17:08:54 +0000 | [diff] [blame] | 12 | |
Eric Fiselier | 324506b | 2016-08-11 03:13:11 +0000 | [diff] [blame] | 13 | // <any> |
| 14 | |
| 15 | // void swap(any &, any &) noexcept |
| 16 | |
| 17 | // swap(...) just wraps any::swap(...). That function is tested elsewhere. |
| 18 | |
| 19 | #include <any> |
| 20 | #include <cassert> |
| 21 | |
Marshall Clow | 7fc6a55 | 2019-05-31 18:35:30 +0000 | [diff] [blame] | 22 | #include "test_macros.h" |
| 23 | |
Eric Fiselier | 324506b | 2016-08-11 03:13:11 +0000 | [diff] [blame] | 24 | using std::any; |
| 25 | using std::any_cast; |
| 26 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 27 | int main(int, char**) |
Eric Fiselier | 324506b | 2016-08-11 03:13:11 +0000 | [diff] [blame] | 28 | { |
| 29 | |
| 30 | { // test noexcept |
| 31 | any a; |
| 32 | static_assert(noexcept(swap(a, a)), "swap(any&, any&) must be noexcept"); |
| 33 | } |
| 34 | { |
| 35 | any a1(1); |
| 36 | any a2(2); |
| 37 | |
| 38 | swap(a1, a2); |
| 39 | |
| 40 | assert(any_cast<int>(a1) == 2); |
| 41 | assert(any_cast<int>(a2) == 1); |
| 42 | } |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 43 | |
| 44 | return 0; |
Eric Fiselier | 324506b | 2016-08-11 03:13:11 +0000 | [diff] [blame] | 45 | } |