File indexing completed on 2026-05-03 08:13:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___FORMAT_FORMATTER_BOOL_H
0011 #define _LIBCPP___FORMAT_FORMATTER_BOOL_H
0012
0013 #include <__algorithm/copy.h>
0014 #include <__assert>
0015 #include <__config>
0016 #include <__format/concepts.h>
0017 #include <__format/format_parse_context.h>
0018 #include <__format/formatter.h>
0019 #include <__format/formatter_integral.h>
0020 #include <__format/parser_std_format_spec.h>
0021 #include <__utility/unreachable.h>
0022
0023 #if _LIBCPP_HAS_LOCALIZATION
0024 # include <__locale>
0025 #endif
0026
0027 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0028 # pragma GCC system_header
0029 #endif
0030
0031 _LIBCPP_BEGIN_NAMESPACE_STD
0032
0033 #if _LIBCPP_STD_VER >= 20
0034
0035 template <__fmt_char_type _CharT>
0036 struct _LIBCPP_TEMPLATE_VIS formatter<bool, _CharT> {
0037 public:
0038 template <class _ParseContext>
0039 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0040 typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_integral);
0041 __format_spec::__process_parsed_bool(__parser_, "a bool");
0042 return __result;
0043 }
0044
0045 template <class _FormatContext>
0046 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(bool __value, _FormatContext& __ctx) const {
0047 switch (__parser_.__type_) {
0048 case __format_spec::__type::__default:
0049 case __format_spec::__type::__string:
0050 return __formatter::__format_bool(__value, __ctx, __parser_.__get_parsed_std_specifications(__ctx));
0051
0052 case __format_spec::__type::__binary_lower_case:
0053 case __format_spec::__type::__binary_upper_case:
0054 case __format_spec::__type::__octal:
0055 case __format_spec::__type::__decimal:
0056 case __format_spec::__type::__hexadecimal_lower_case:
0057 case __format_spec::__type::__hexadecimal_upper_case:
0058
0059
0060 return __formatter::__format_integer(
0061 static_cast<unsigned>(__value), __ctx, __parser_.__get_parsed_std_specifications(__ctx));
0062
0063 default:
0064 _LIBCPP_ASSERT_INTERNAL(false, "The parse function should have validated the type");
0065 __libcpp_unreachable();
0066 }
0067 }
0068
0069 __format_spec::__parser<_CharT> __parser_;
0070 };
0071
0072 # if _LIBCPP_STD_VER >= 23
0073 template <>
0074 inline constexpr bool enable_nonlocking_formatter_optimization<bool> = true;
0075 # endif
0076 #endif
0077
0078 _LIBCPP_END_NAMESPACE_STD
0079
0080 #endif