File indexing completed on 2026-05-03 08:14:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___THREAD_FORMATTER_H
0011 #define _LIBCPP___THREAD_FORMATTER_H
0012
0013 #include <__concepts/arithmetic.h>
0014 #include <__config>
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/parser_std_format_spec.h>
0020 #include <__thread/id.h>
0021 #include <__type_traits/conditional.h>
0022 #include <__type_traits/is_pointer.h>
0023 #include <__type_traits/is_same.h>
0024 #include <cstdint>
0025
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 # pragma GCC system_header
0028 #endif
0029
0030 #if _LIBCPP_STD_VER >= 23
0031
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033
0034 # if _LIBCPP_HAS_THREADS
0035
0036 template <__fmt_char_type _CharT>
0037 struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {
0038 public:
0039 template <class _ParseContext>
0040 _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0041 return __parser_.__parse(__ctx, __format_spec::__fields_fill_align_width);
0042 }
0043
0044 template <class _FormatContext>
0045 _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(__thread_id __id, _FormatContext& __ctx) const {
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 using _Tp = decltype(__get_underlying_id(__id));
0060 using _Cp = conditional_t<integral<_Tp>, _Tp, conditional_t<is_pointer_v<_Tp>, uintptr_t, void>>;
0061 static_assert(!is_same_v<_Cp, void>, "unsupported thread::id type, please file a bug report");
0062
0063 __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
0064 if constexpr (is_pointer_v<_Tp>) {
0065 __specs.__std_.__alternate_form_ = true;
0066 __specs.__std_.__type_ = __format_spec::__type::__hexadecimal_lower_case;
0067 }
0068 return __formatter::__format_integer(reinterpret_cast<_Cp>(__get_underlying_id(__id)), __ctx, __specs);
0069 }
0070
0071 __format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};
0072 };
0073
0074 # endif
0075
0076 _LIBCPP_END_NAMESPACE_STD
0077
0078 #endif
0079
0080 #endif