• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
11 
12 // <any>
13 
14 // any::has_value() noexcept
15 
16 #include <any>
17 #include <cassert>
18 
19 #include "any_helpers.h"
20 
main()21 int main()
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