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_data.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 _ParseContext>
27_LIBCPP_HIDE_FROM_ABI constexpr
28 typename _ParseContext::iterator __formatter_bool_parse(__format_spec::__parser_data<_CharT>&, _ParseContext&);
29
30template <__fmt_char_type _CharT, class _FormatContext>
31_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
32__formatter_bool_format(bool __value, __format_spec::__parser_data<_CharT>, _FormatContext&);
33
34template <__fmt_char_type _CharT>
35struct formatter<bool, _CharT> {
36 template <class _ParseContext>
37 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
38 return std::__formatter_bool_parse(__parser_, __ctx);
39 }
40
41 template <class _FormatContext>
42 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(bool __value, _FormatContext& __ctx) const {
43 return std::__formatter_bool_format(__value, __parser_, __ctx);
44 }
45
46 __format_spec::__parser_data<_CharT> __parser_;
47};
48
49# if _LIBCPP_STD_VER >= 23
50template <>
51inline constexpr bool enable_nonlocking_formatter_optimization<bool> = true;
52# endif // _LIBCPP_STD_VER >= 23
53#endif // _LIBCPP_STD_VER >= 20
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif // _LIBCPP___FORMAT_FORMATTER_BOOL_H
58