Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:29

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___FORMAT_FORMATTER_BOOL_H
0011 #define _LIBCPP___CXX03___FORMAT_FORMATTER_BOOL_H
0012 
0013 #include <__cxx03/__algorithm/copy.h>
0014 #include <__cxx03/__assert>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__format/concepts.h>
0017 #include <__cxx03/__format/format_parse_context.h>
0018 #include <__cxx03/__format/formatter.h>
0019 #include <__cxx03/__format/formatter_integral.h>
0020 #include <__cxx03/__format/parser_std_format_spec.h>
0021 #include <__cxx03/__utility/unreachable.h>
0022 
0023 #ifndef _LIBCPP_HAS_NO_LOCALIZATION
0024 #  include <__cxx03/__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       // Promotes bool to an integral type. This reduces the number of
0059       // instantiations of __format_integer reducing code size.
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 #endif //_LIBCPP_STD_VER >= 20
0073 
0074 _LIBCPP_END_NAMESPACE_STD
0075 
0076 #endif // _LIBCPP___CXX03___FORMAT_FORMATTER_BOOL_H