xref: /llvm-project/libcxx/test/std/utilities/any/any.class/any.observers/has_value.pass.cpp (revision 3581fd32ee95ce282b816d35008ca2d0d42e2775)
1324506b9SEric Fiselier //===----------------------------------------------------------------------===//
2324506b9SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6324506b9SEric Fiselier //
7324506b9SEric Fiselier //===----------------------------------------------------------------------===//
8324506b9SEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10324506b9SEric Fiselier 
11324506b9SEric Fiselier // <any>
12324506b9SEric Fiselier 
13324506b9SEric Fiselier // any::has_value() noexcept
14324506b9SEric Fiselier 
15324506b9SEric Fiselier #include <any>
16324506b9SEric Fiselier #include <cassert>
17324506b9SEric Fiselier 
187fc6a556SMarshall Clow #include "test_macros.h"
19324506b9SEric Fiselier #include "any_helpers.h"
20324506b9SEric Fiselier 
main(int,char **)212df59c50SJF Bastien int main(int, char**)
22324506b9SEric Fiselier {
23324506b9SEric Fiselier     {
24*3581fd32SArthur O'Dwyer         std::any a;
25*3581fd32SArthur O'Dwyer         ASSERT_NOEXCEPT(a.has_value());
26324506b9SEric Fiselier     }
27324506b9SEric Fiselier     // empty
28324506b9SEric Fiselier     {
29*3581fd32SArthur O'Dwyer         std::any a;
30324506b9SEric Fiselier         assert(!a.has_value());
31324506b9SEric Fiselier 
32324506b9SEric Fiselier         a.reset();
33324506b9SEric Fiselier         assert(!a.has_value());
34324506b9SEric Fiselier 
35324506b9SEric Fiselier         a = 42;
36324506b9SEric Fiselier         assert(a.has_value());
37324506b9SEric Fiselier     }
38324506b9SEric Fiselier     // small object
39324506b9SEric Fiselier     {
40*3581fd32SArthur O'Dwyer         std::any a = small(1);
41324506b9SEric Fiselier         assert(a.has_value());
42324506b9SEric Fiselier 
43324506b9SEric Fiselier         a.reset();
44324506b9SEric Fiselier         assert(!a.has_value());
45324506b9SEric Fiselier 
46*3581fd32SArthur O'Dwyer         a = small(1);
47324506b9SEric Fiselier         assert(a.has_value());
48324506b9SEric Fiselier     }
49324506b9SEric Fiselier     // large object
50324506b9SEric Fiselier     {
51*3581fd32SArthur O'Dwyer         std::any a = large(1);
52324506b9SEric Fiselier         assert(a.has_value());
53324506b9SEric Fiselier 
54324506b9SEric Fiselier         a.reset();
55324506b9SEric Fiselier         assert(!a.has_value());
56324506b9SEric Fiselier 
57*3581fd32SArthur O'Dwyer         a = large(1);
58324506b9SEric Fiselier         assert(a.has_value());
59324506b9SEric Fiselier     }
602df59c50SJF Bastien 
612df59c50SJF Bastien   return 0;
62324506b9SEric Fiselier }
63