[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / libcxx / include / __format / formatter_bool.h
blobd08acd474439ca54780951b111cc0a1089e5dda8
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FORMAT_FORMATTER_BOOL_H
11 #define _LIBCPP___FORMAT_FORMATTER_BOOL_H
13 #include <__algorithm/copy.h>
14 #include <__assert>
15 #include <__config>
16 #include <__format/concepts.h>
17 #include <__format/format_parse_context.h>
18 #include <__format/formatter.h>
19 #include <__format/formatter_integral.h>
20 #include <__format/parser_std_format_spec.h>
21 #include <__utility/unreachable.h>
23 #if _LIBCPP_HAS_LOCALIZATION
24 # include <__locale>
25 #endif
27 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 # pragma GCC system_header
29 #endif
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 #if _LIBCPP_STD_VER >= 20
35 template <__fmt_char_type _CharT>
36 struct _LIBCPP_TEMPLATE_VIS formatter<bool, _CharT> {
37 public:
38 template <class _ParseContext>
39 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
40 typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_integral);
41 __format_spec::__process_parsed_bool(__parser_, "a bool");
42 return __result;
45 template <class _FormatContext>
46 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(bool __value, _FormatContext& __ctx) const {
47 switch (__parser_.__type_) {
48 case __format_spec::__type::__default:
49 case __format_spec::__type::__string:
50 return __formatter::__format_bool(__value, __ctx, __parser_.__get_parsed_std_specifications(__ctx));
52 case __format_spec::__type::__binary_lower_case:
53 case __format_spec::__type::__binary_upper_case:
54 case __format_spec::__type::__octal:
55 case __format_spec::__type::__decimal:
56 case __format_spec::__type::__hexadecimal_lower_case:
57 case __format_spec::__type::__hexadecimal_upper_case:
58 // Promotes bool to an integral type. This reduces the number of
59 // instantiations of __format_integer reducing code size.
60 return __formatter::__format_integer(
61 static_cast<unsigned>(__value), __ctx, __parser_.__get_parsed_std_specifications(__ctx));
63 default:
64 _LIBCPP_ASSERT_INTERNAL(false, "The parse function should have validated the type");
65 __libcpp_unreachable();
69 __format_spec::__parser<_CharT> __parser_;
72 # if _LIBCPP_STD_VER >= 23
73 template <>
74 inline constexpr bool enable_nonlocking_formatter_optimization<bool> = true;
75 # endif // _LIBCPP_STD_VER >= 23
76 #endif // _LIBCPP_STD_VER >= 20
78 _LIBCPP_END_NAMESPACE_STD
80 #endif // _LIBCPP___FORMAT_FORMATTER_BOOL_H