• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main(int,char **)21 int main(int, char**)
22 {
23     using std::any;
24     // noexcept test
25     {
26         any a;
27         static_assert(noexcept(a.has_value()), "any::has_value() must be noexcept");
28     }
29     // empty
30     {
31         any a;
32         assert(!a.has_value());
33 
34         a.reset();
35         assert(!a.has_value());
36 
37         a = 42;
38         assert(a.has_value());
39     }
40     // small object
41     {
42         small const s(1);
43         any a(s);
44         assert(a.has_value());
45 
46         a.reset();
47         assert(!a.has_value());
48 
49         a = s;
50         assert(a.has_value());
51     }
52     // large object
53     {
54         large const l(1);
55         any a(l);
56         assert(a.has_value());
57 
58         a.reset();
59         assert(!a.has_value());
60 
61         a = l;
62         assert(a.has_value());
63     }
64 
65   return 0;
66 }
67