Debian Codegraph @

libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.operator_bool.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, c++17, c++20, c++23
10
11 // <charconv>
12
13 // struct from_chars_result
14 // constexpr explicit operator bool() const noexcept { return ec == errc{}; }
15
16 #include <charconv>
17
18 #include <cassert>
19 #include <type_traits>
20
21 #include "test_macros.h"
22
23 static_assert(!std::is_convertible_v<std::from_chars_result, bool>);
24 static_assert(std::is_constructible_v<bool, std::from_chars_result>);
25
26 constexpr bool test() {
27 // True
28 {
29 std::from_chars_result value{nullptr, std::errc{}};
30 assert(bool(value) == true);
31 static_assert(noexcept(bool(value)) == true);
32 }
33 // False
34 {
35 std::from_chars_result value{nullptr, std::errc::value_too_large};
36 assert(bool(value) == false);
37 static_assert(noexcept(bool(value)) == true);
38 }
39
40 return true;
41 }
42
43 int main(int, char**) {
44 assert(test());
45 static_assert(test());
46
47 return 0;
48 }