Back to home page

EIC code displayed by LXR

 
 

    


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

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___FORMAT_FORMATTER_POINTER_H
0011 #define _LIBCPP___FORMAT_FORMATTER_POINTER_H
0012 
0013 #include <__config>
0014 #include <__cstddef/nullptr_t.h>
0015 #include <__format/concepts.h>
0016 #include <__format/format_parse_context.h>
0017 #include <__format/formatter.h>
0018 #include <__format/formatter_integral.h>
0019 #include <__format/formatter_output.h>
0020 #include <__format/parser_std_format_spec.h>
0021 #include <cstdint>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 #if _LIBCPP_STD_VER >= 20
0030 
0031 template <__fmt_char_type _CharT>
0032 struct _LIBCPP_TEMPLATE_VIS __formatter_pointer {
0033 public:
0034   template <class _ParseContext>
0035   _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0036     typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_pointer);
0037     __format_spec::__process_display_type_pointer(__parser_.__type_, "a pointer");
0038     return __result;
0039   }
0040 
0041   template <class _FormatContext>
0042   _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const void* __ptr, _FormatContext& __ctx) const {
0043     __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
0044     __specs.__std_.__alternate_form_                       = true;
0045     __specs.__std_.__type_ =
0046         __specs.__std_.__type_ == __format_spec::__type::__pointer_upper_case
0047             ? __format_spec::__type::__hexadecimal_upper_case
0048             : __format_spec::__type::__hexadecimal_lower_case;
0049 
0050     return __formatter::__format_integer(reinterpret_cast<uintptr_t>(__ptr), __ctx, __specs);
0051   }
0052 
0053   __format_spec::__parser<_CharT> __parser_;
0054 };
0055 
0056 // [format.formatter.spec]/2.4
0057 // For each charT, the pointer type specializations template<>
0058 // - struct formatter<nullptr_t, charT>;
0059 // - template<> struct formatter<void*, charT>;
0060 // - template<> struct formatter<const void*, charT>;
0061 template <__fmt_char_type _CharT>
0062 struct _LIBCPP_TEMPLATE_VIS formatter<nullptr_t, _CharT> : public __formatter_pointer<_CharT> {};
0063 template <__fmt_char_type _CharT>
0064 struct _LIBCPP_TEMPLATE_VIS formatter<void*, _CharT> : public __formatter_pointer<_CharT> {};
0065 template <__fmt_char_type _CharT>
0066 struct _LIBCPP_TEMPLATE_VIS formatter<const void*, _CharT> : public __formatter_pointer<_CharT> {};
0067 
0068 #  if _LIBCPP_STD_VER >= 23
0069 template <>
0070 inline constexpr bool enable_nonlocking_formatter_optimization<nullptr_t> = true;
0071 template <>
0072 inline constexpr bool enable_nonlocking_formatter_optimization<void*> = true;
0073 template <>
0074 inline constexpr bool enable_nonlocking_formatter_optimization<const void*> = true;
0075 #  endif // _LIBCPP_STD_VER >= 23
0076 #endif   // _LIBCPP_STD_VER >= 20
0077 
0078 _LIBCPP_END_NAMESPACE_STD
0079 
0080 #endif // _LIBCPP___FORMAT_FORMATTER_POINTER_H