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_INTEGER_H
0011 #define _LIBCPP___CXX03___FORMAT_FORMATTER_INTEGER_H
0012 
0013 #include <__cxx03/__concepts/arithmetic.h>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__format/concepts.h>
0016 #include <__cxx03/__format/format_parse_context.h>
0017 #include <__cxx03/__format/formatter.h>
0018 #include <__cxx03/__format/formatter_integral.h>
0019 #include <__cxx03/__format/formatter_output.h>
0020 #include <__cxx03/__format/parser_std_format_spec.h>
0021 #include <__cxx03/__type_traits/is_void.h>
0022 #include <__cxx03/__type_traits/make_32_64_or_128_bit.h>
0023 
0024 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0025 #  pragma GCC system_header
0026 #endif
0027 
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029 
0030 #if _LIBCPP_STD_VER >= 20
0031 
0032 template <__fmt_char_type _CharT>
0033 struct _LIBCPP_TEMPLATE_VIS __formatter_integer {
0034 public:
0035   template <class _ParseContext>
0036   _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0037     typename _ParseContext::iterator __result = __parser_.__parse(__ctx, __format_spec::__fields_integral);
0038     __format_spec::__process_parsed_integer(__parser_, "an integer");
0039     return __result;
0040   }
0041 
0042   template <integral _Tp, class _FormatContext>
0043   _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(_Tp __value, _FormatContext& __ctx) const {
0044     __format_spec::__parsed_specifications<_CharT> __specs = __parser_.__get_parsed_std_specifications(__ctx);
0045 
0046     if (__specs.__std_.__type_ == __format_spec::__type::__char)
0047       return __formatter::__format_char(__value, __ctx.out(), __specs);
0048 
0049     using _Type = __make_32_64_or_128_bit_t<_Tp>;
0050     static_assert(!is_void<_Type>::value, "unsupported integral type used in __formatter_integer::__format");
0051 
0052     // Reduce the number of instantiation of the integer formatter
0053     return __formatter::__format_integer(static_cast<_Type>(__value), __ctx, __specs);
0054   }
0055 
0056   __format_spec::__parser<_CharT> __parser_;
0057 };
0058 
0059 // Signed integral types.
0060 template <__fmt_char_type _CharT>
0061 struct _LIBCPP_TEMPLATE_VIS formatter<signed char, _CharT> : public __formatter_integer<_CharT> {};
0062 template <__fmt_char_type _CharT>
0063 struct _LIBCPP_TEMPLATE_VIS formatter<short, _CharT> : public __formatter_integer<_CharT> {};
0064 template <__fmt_char_type _CharT>
0065 struct _LIBCPP_TEMPLATE_VIS formatter<int, _CharT> : public __formatter_integer<_CharT> {};
0066 template <__fmt_char_type _CharT>
0067 struct _LIBCPP_TEMPLATE_VIS formatter<long, _CharT> : public __formatter_integer<_CharT> {};
0068 template <__fmt_char_type _CharT>
0069 struct _LIBCPP_TEMPLATE_VIS formatter<long long, _CharT> : public __formatter_integer<_CharT> {};
0070 #  ifndef _LIBCPP_HAS_NO_INT128
0071 template <__fmt_char_type _CharT>
0072 struct _LIBCPP_TEMPLATE_VIS formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {};
0073 #  endif
0074 
0075 // Unsigned integral types.
0076 template <__fmt_char_type _CharT>
0077 struct _LIBCPP_TEMPLATE_VIS formatter<unsigned char, _CharT> : public __formatter_integer<_CharT> {};
0078 template <__fmt_char_type _CharT>
0079 struct _LIBCPP_TEMPLATE_VIS formatter<unsigned short, _CharT> : public __formatter_integer<_CharT> {};
0080 template <__fmt_char_type _CharT>
0081 struct _LIBCPP_TEMPLATE_VIS formatter<unsigned, _CharT> : public __formatter_integer<_CharT> {};
0082 template <__fmt_char_type _CharT>
0083 struct _LIBCPP_TEMPLATE_VIS formatter<unsigned long, _CharT> : public __formatter_integer<_CharT> {};
0084 template <__fmt_char_type _CharT>
0085 struct _LIBCPP_TEMPLATE_VIS formatter<unsigned long long, _CharT> : public __formatter_integer<_CharT> {};
0086 #  ifndef _LIBCPP_HAS_NO_INT128
0087 template <__fmt_char_type _CharT>
0088 struct _LIBCPP_TEMPLATE_VIS formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {};
0089 #  endif
0090 
0091 #endif //_LIBCPP_STD_VER >= 20
0092 
0093 _LIBCPP_END_NAMESPACE_STD
0094 
0095 #endif // _LIBCPP___CXX03___FORMAT_FORMATTER_INTEGER_H