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

source code of libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.operator_bool.pass.cpp