Debian Codegraph @

libcxx/test/std/utilities/expected/expected.void/observers/deref.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9
10 // constexpr void operator*() const & noexcept;
11
12 #include <cassert>
13 #include <concepts>
14 #include <expected>
15 #include <type_traits>
16 #include <utility>
17
18 #include "test_macros.h"
19
20 // Test noexcept
21 template <class T>
22 concept DerefNoexcept =
23 requires(T t) {
24 { std::forward<T>(t).operator*() } noexcept;
25 };
26
27 static_assert(!DerefNoexcept<int>);
28
29 static_assert(DerefNoexcept<std::expected<void, int>>);
30
31 constexpr bool test() {
32 const std::expected<void, int> e;
33 *e;
34 static_assert(std::is_same_v<decltype(*e), void>);
35
36 return true;
37 }
38
39 int main(int, char**) {
40 test();
41 static_assert(test());
42 return 0;
43 }