[clang] Add tracking source deduction guide for the explicitly-written
[llvm-project.git] / libcxx / test / std / utilities / charconv / charconv.syn / from_chars_result.operator_bool.pass.cpp
blobe0f20f1e8e3ff53b6af3e36031f3926a44d1b385
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
11 // <charconv>
13 // struct from_chars_result
14 // constexpr explicit operator bool() const noexcept { return ec == errc{}; }
16 #include <charconv>
18 #include <cassert>
19 #include <system_error>
20 #include <type_traits>
22 #include "test_macros.h"
24 static_assert(!std::is_convertible_v<std::from_chars_result, bool>);
25 static_assert(std::is_constructible_v<bool, std::from_chars_result>);
27 constexpr bool test() {
28 // True
30 std::from_chars_result value{nullptr, std::errc{}};
31 assert(bool(value) == true);
32 static_assert(noexcept(bool(value)) == true);
34 // False
36 std::from_chars_result value{nullptr, std::errc::value_too_large};
37 assert(bool(value) == false);
38 static_assert(noexcept(bool(value)) == true);
41 return true;
44 int main(int, char**) {
45 assert(test());
46 static_assert(test());
48 return 0;