Path: blob/main/contrib/llvm-project/libcxx/include/__thread/formatter.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___THREAD_FORMATTER_H10#define _LIBCPP___THREAD_FORMATTER_H1112#include <__concepts/arithmetic.h>13#include <__config>14#include <__format/concepts.h>15#include <__format/format_parse_context.h>16#include <__format/formatter.h>17#include <__format/formatter_integral.h>18#include <__format/parser_std_format_spec.h>19#include <__thread/id.h>20#include <__type_traits/conditional.h>21#include <__type_traits/is_pointer.h>22#include <__type_traits/is_same.h>23#include <cstdint>2425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)26# pragma GCC system_header27#endif2829#if _LIBCPP_STD_VER >= 233031_LIBCPP_BEGIN_NAMESPACE_STD3233# ifndef _LIBCPP_HAS_NO_THREADS3435template <__fmt_char_type _CharT>36struct _LIBCPP_TEMPLATE_VIS formatter<__thread_id, _CharT> {37public:38template <class _ParseContext>39_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {40return __parser_.__parse(__ctx, __format_spec::__fields_fill_align_width);41}4243template <class _FormatContext>44_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(__thread_id __id, _FormatContext& __ctx) const {45// In __thread/support/pthread.h, __libcpp_thread_id is either a46// unsigned long long or a pthread_t.47//48// The type of pthread_t is left unspecified in POSIX so it can be any49// type. The most logical types are an integral or pointer.50// On Linux systems pthread_t is an unsigned long long.51// On Apple systems pthread_t is a pointer type.52//53// Note the output should match what the stream operator does. Since54// the ostream operator has been shipped years before this formatter55// was added to the Standard, this formatter does what the stream56// operator does. This may require platform specific changes.5758using _Tp = decltype(__get_underlying_id(__id));59using _Cp = conditional_t<integral<_Tp>, _Tp, conditional_t<is_pointer_v<_Tp>, uintptr_t, void>>;60static_assert(!is_same_v<_Cp, void>, "unsupported thread::id type, please file a bug report");6162__format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);63if constexpr (is_pointer_v<_Tp>) {64__specs.__std_.__alternate_form_ = true;65__specs.__std_.__type_ = __format_spec::__type::__hexadecimal_lower_case;66}67return __formatter::__format_integer(reinterpret_cast<_Cp>(__get_underlying_id(__id)), __ctx, __specs);68}6970__format_spec::__parser<_CharT> __parser_{.__alignment_ = __format_spec::__alignment::__right};71};7273# endif // !_LIBCPP_HAS_NO_THREADS7475_LIBCPP_END_NAMESPACE_STD7677#endif // _LIBCPP_STD_VER >= 237879#endif // _LIBCPP___THREAD_FORMATTER_H808182