Debian Codegraph @

libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp

raw
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 // any::has_value() noexcept
14
15 #include <any>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "any_helpers.h"
20
21 int main(int, char**)
22 {
23 {
24 std::any a;
25 ASSERT_NOEXCEPT(a.has_value());
26 }
27 // empty
28 {
29 std::any a;
30 assert(!a.has_value());
31
32 a.reset();
33 assert(!a.has_value());
34
35 a = 42;
36 assert(a.has_value());
37 }
38 // small object
39 {
40 std::any a = small(1);
41 assert(a.has_value());
42
43 a.reset();
44 assert(!a.has_value());
45
46 a = small(1);
47 assert(a.has_value());
48 }
49 // large object
50 {
51 std::any a = large(1);
52 assert(a.has_value());
53
54 a.reset();
55 assert(!a.has_value());
56
57 a = large(1);
58 assert(a.has_value());
59 }
60
61 return 0;
62 }