aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__format/formatter_pointer.h
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/__format/formatter_pointer.h')
-rw-r--r--libcxx/include/__format/formatter_pointer.h62
1 files changed, 22 insertions, 40 deletions
diff --git a/libcxx/include/__format/formatter_pointer.h b/libcxx/include/__format/formatter_pointer.h
index aa2eb641c6c6..3cd4c9bba960 100644
--- a/libcxx/include/__format/formatter_pointer.h
+++ b/libcxx/include/__format/formatter_pointer.h
@@ -10,17 +10,15 @@
#ifndef _LIBCPP___FORMAT_FORMATTER_POINTER_H
#define _LIBCPP___FORMAT_FORMATTER_POINTER_H
-#include <__algorithm/copy.h>
#include <__availability>
#include <__config>
-#include <__debug>
-#include <__format/format_error.h>
#include <__format/format_fwd.h>
+#include <__format/format_parse_context.h>
#include <__format/formatter.h>
#include <__format/formatter_integral.h>
+#include <__format/formatter_output.h>
#include <__format/parser_std_format_spec.h>
-#include <__iterator/access.h>
-#include <__nullptr>
+#include <cstddef>
#include <cstdint>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -31,41 +29,27 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
-// TODO FMT Remove this once we require compilers with proper C++20 support.
-// If the compiler has no concepts support, the format header will be disabled.
-// Without concepts support enable_if needs to be used and that too much effort
-// to support compilers with partial C++20 support.
-# if !defined(_LIBCPP_HAS_NO_CONCEPTS)
-
-namespace __format_spec {
-
template <__formatter::__char_type _CharT>
-class _LIBCPP_TEMPLATE_VIS __formatter_pointer : public __parser_pointer<_CharT> {
+struct _LIBCPP_TEMPLATE_VIS __formatter_pointer {
public:
- _LIBCPP_HIDE_FROM_ABI auto format(const void* __ptr, auto& __ctx) -> decltype(__ctx.out()) {
- _LIBCPP_ASSERT(this->__alignment != _Flags::_Alignment::__default,
- "The call to parse should have updated the alignment");
- if (this->__width_needs_substitution())
- this->__substitute_width_arg_id(__ctx.arg(this->__width));
+ constexpr __formatter_pointer() { __parser_.__alignment_ = __format_spec::__alignment::__right; }
- // This code looks a lot like the code to format a hexadecimal integral,
- // but that code isn't public. Making that code public requires some
- // refactoring.
- // TODO FMT Remove code duplication.
- char __buffer[2 + 2 * sizeof(uintptr_t)];
- __buffer[0] = '0';
- __buffer[1] = 'x';
- char* __last = __to_buffer(__buffer + 2, _VSTD::end(__buffer), reinterpret_cast<uintptr_t>(__ptr), 16);
-
- unsigned __size = __last - __buffer;
- if (__size >= this->__width)
- return _VSTD::copy(__buffer, __last, __ctx.out());
+ _LIBCPP_HIDE_FROM_ABI constexpr auto
+ parse(basic_format_parse_context<_CharT>& __parse_ctx) -> decltype(__parse_ctx.begin()) {
+ auto __result = __parser_.__parse(__parse_ctx, __format_spec::__fields_pointer);
+ __format_spec::__process_display_type_pointer(__parser_.__type_);
+ return __result;
+ }
- return __formatter::__write(__ctx.out(), __buffer, __last, __size, this->__width, this->__fill, this->__alignment);
+ _LIBCPP_HIDE_FROM_ABI auto format(const void* __ptr, auto& __ctx) const -> decltype(__ctx.out()) {
+ __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
+ __specs.__std_.__alternate_form_ = true;
+ __specs.__std_.__type_ = __format_spec::__type::__hexadecimal_lower_case;
+ return __formatter::__format_integer(reinterpret_cast<uintptr_t>(__ptr), __ctx, __specs);
}
-};
-} // namespace __format_spec
+ __format_spec::__parser<_CharT> __parser_;
+};
// [format.formatter.spec]/2.4
// For each charT, the pointer type specializations template<>
@@ -74,15 +58,13 @@ public:
// - template<> struct formatter<const void*, charT>;
template <__formatter::__char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<nullptr_t, _CharT>
- : public __format_spec::__formatter_pointer<_CharT> {};
+ : public __formatter_pointer<_CharT> {};
template <__formatter::__char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<void*, _CharT>
- : public __format_spec::__formatter_pointer<_CharT> {};
+struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<void*, _CharT> : public __formatter_pointer<_CharT> {
+};
template <__formatter::__char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter<const void*, _CharT>
- : public __format_spec::__formatter_pointer<_CharT> {};
-
-# endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
+ : public __formatter_pointer<_CharT> {};
#endif //_LIBCPP_STD_VER > 17