1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FORMAT_FORMATTER_BOOL_H
11#define _LIBCPP___FORMAT_FORMATTER_BOOL_H
12
13#include <__config>
14#include <__format/concepts.h>
15#include <__format/formatter.h>
16#include <__format/parser_std_format_spec.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#if _LIBCPP_STD_VER >= 20
25
26template <__fmt_char_type _CharT, class _FormatContext>
27_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
28__formatter_bool_format(bool __value, __format_spec::__parser<_CharT>, _FormatContext&);
29
30template <__fmt_char_type _CharT>
31struct formatter<bool, _CharT> {
32 template <class _ParseContext>
33 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
34 typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_integral);
35 __format_spec::__process_parsed_bool(__parser_, "a bool");
36 return __result;
37 }
38
39 template <class _FormatContext>
40 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(bool __value, _FormatContext& __ctx) const {
41 return std::__formatter_bool_format(__value, __parser_, __ctx);
42 }
43
44 __format_spec::__parser<_CharT> __parser_;
45};
46
47# if _LIBCPP_STD_VER >= 23
48template <>
49inline constexpr bool enable_nonlocking_formatter_optimization<bool> = true;
50# endif // _LIBCPP_STD_VER >= 23
51#endif // _LIBCPP_STD_VER >= 20
52
53_LIBCPP_END_NAMESPACE_STD
54
55#endif // _LIBCPP___FORMAT_FORMATTER_BOOL_H
56