blob: 1e982235f4a237292eae0e15c76ca436150731cd [file] [log] [blame]
Eric Fiselier324506b2016-08-11 03:13:11 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Fiselier324506b2016-08-11 03:13:11 +00006//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++98, c++03, c++11, c++14
10
Louis Dionnef5f2f772019-02-05 20:11:58 +000011// XFAIL: dylib-has-no-bad_any_cast && !libcpp-no-exceptions
Mehdi Aminie9c66ad2017-05-04 17:08:54 +000012
Eric Fiselier324506b2016-08-11 03:13:11 +000013// <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 Clow7fc6a552019-05-31 18:35:30 +000022#include "test_macros.h"
23
Eric Fiselier324506b2016-08-11 03:13:11 +000024using std::any;
25using std::any_cast;
26
JF Bastien2df59c52019-02-04 20:31:13 +000027int main(int, char**)
Eric Fiselier324506b2016-08-11 03:13:11 +000028{
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 Bastien2df59c52019-02-04 20:31:13 +000043
44 return 0;
Eric Fiselier324506b2016-08-11 03:13:11 +000045}