From b3d39330af3ffffa06beea2cc43a31a85c6dbadb Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 4 Apr 2024 01:36:06 -0400
Subject: [PATCH] build(c): bump vendored fmt
This should fix a clang-18-only deprecation warning.
---
c/driver/framework/base.h | 2 +-
c/vendor/fmt/.gitignore | 24 +
c/vendor/fmt/CMakeLists.txt | 22 +-
c/vendor/fmt/ChangeLog.md | 7 +-
c/vendor/fmt/README.md | 59 +-
c/vendor/fmt/include/fmt/args.h | 2 +-
c/vendor/fmt/include/fmt/base.h | 3068 +++++++++++++++++++++++++
c/vendor/fmt/include/fmt/chrono.h | 329 ++-
c/vendor/fmt/include/fmt/color.h | 91 +-
c/vendor/fmt/include/fmt/compile.h | 10 +-
c/vendor/fmt/include/fmt/core.h | 2972 +-----------------------
c/vendor/fmt/include/fmt/format-inl.h | 255 +-
c/vendor/fmt/include/fmt/format.h | 1045 ++++-----
c/vendor/fmt/include/fmt/os.h | 37 +-
c/vendor/fmt/include/fmt/ostream.h | 48 +-
c/vendor/fmt/include/fmt/printf.h | 184 +-
c/vendor/fmt/include/fmt/ranges.h | 257 ++-
c/vendor/fmt/include/fmt/std.h | 142 +-
c/vendor/fmt/include/fmt/xchar.h | 130 +-
c/vendor/fmt/src/fmt.cc | 12 +-
c/vendor/fmt/src/os.cc | 63 +-
c/vendor/vendor_fmt.sh | 3 +-
22 files changed, 4697 insertions(+), 4065 deletions(-)
create mode 100644 c/vendor/fmt/.gitignore
create mode 100644 c/vendor/fmt/include/fmt/base.h
diff --git a/c/driver/framework/base.h b/c/driver/framework/base.h
index e416f89d0c..fcc385ac62 100644
--- a/c/driver/framework/base.h
+++ b/c/driver/framework/base.h
@@ -627,7 +627,7 @@ class Driver {
/// \brief Formatter for Option values.
template <>
struct fmt::formatter : fmt::nested_formatter {
- auto format(const adbc::driver::Option& option, fmt::format_context& ctx) {
+ auto format(const adbc::driver::Option& option, fmt::format_context& ctx) const {
return write_padded(ctx, [=](auto out) {
return std::visit(
[&](auto&& value) {
diff --git a/c/vendor/fmt/.gitignore b/c/vendor/fmt/.gitignore
new file mode 100644
index 0000000000..1406ac347f
--- /dev/null
+++ b/c/vendor/fmt/.gitignore
@@ -0,0 +1,24 @@
+*.a
+*.so*
+*.xcodeproj
+*~
+.vscode/
+/CMakeScripts
+/Testing
+/_CPack_Packages
+/doc/doxyxml
+/doc/html
+/doc/node_modules
+/install_manifest.txt
+CMakeCache.txt
+CMakeFiles
+CPack*.cmake
+CTestTestfile.cmake
+FMT.build
+Makefile
+bin/
+build/
+cmake_install.cmake
+fmt-*.cmake
+fmt.pc
+virtualenv
diff --git a/c/vendor/fmt/CMakeLists.txt b/c/vendor/fmt/CMakeLists.txt
index 0c3005cec6..00b965f075 100644
--- a/c/vendor/fmt/CMakeLists.txt
+++ b/c/vendor/fmt/CMakeLists.txt
@@ -150,7 +150,7 @@ option(FMT_INSTALL "Generate the install target." ON)
option(FMT_TEST "Generate the test target." ${FMT_MASTER_PROJECT})
option(FMT_FUZZ "Generate the fuzz target." OFF)
option(FMT_CUDA_TEST "Generate the cuda-test target." OFF)
-option(FMT_OS "Include core requiring OS (Windows/Posix) " ON)
+option(FMT_OS "Include OS-specific APIs." ON)
option(FMT_MODULE "Build a module instead of a traditional library." OFF)
option(FMT_SYSTEM_HEADERS "Expose headers with marking them as system." OFF)
@@ -167,10 +167,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "MSDOS")
message(STATUS "MSDOS is incompatible with gtest")
endif ()
-# Get version from core.h
-file(READ include/fmt/core.h core_h)
-if (NOT core_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])")
- message(FATAL_ERROR "Cannot get FMT_VERSION from core.h.")
+# Get version from base.h
+file(READ include/fmt/base.h base_h)
+if (NOT base_h MATCHES "FMT_VERSION ([0-9]+)([0-9][0-9])([0-9][0-9])")
+ message(FATAL_ERROR "Cannot get FMT_VERSION from base.h.")
endif ()
# Use math to skip leading zeros if any.
math(EXPR CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
@@ -178,7 +178,7 @@ math(EXPR CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
math(EXPR CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
join(FMT_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.
${CPACK_PACKAGE_VERSION_PATCH})
-message(STATUS "Version: ${FMT_VERSION}")
+message(STATUS "{fmt} version: ${FMT_VERSION}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
@@ -274,13 +274,10 @@ function(add_headers VAR)
endfunction()
# Define the fmt library, its includes and the needed defines.
-add_headers(FMT_HEADERS args.h chrono.h color.h compile.h core.h format.h
+add_headers(FMT_HEADERS args.h base.h chrono.h color.h compile.h core.h format.h
format-inl.h os.h ostream.h printf.h ranges.h std.h
xchar.h)
set(FMT_SOURCES src/format.cc)
-if (FMT_OS)
- set(FMT_SOURCES ${FMT_SOURCES} src/os.cc)
-endif ()
add_module_library(fmt src/fmt.cc FALLBACK
${FMT_SOURCES} ${FMT_HEADERS} README.md ChangeLog.md
@@ -289,6 +286,11 @@ add_library(fmt::fmt ALIAS fmt)
if (FMT_MODULE)
enable_module(fmt)
endif ()
+if (FMT_OS)
+ target_sources(fmt PRIVATE src/os.cc)
+else()
+ target_compile_definitions(fmt PRIVATE FMT_OS=0)
+endif ()
if (FMT_WERROR)
target_compile_options(fmt PRIVATE ${WERROR_FLAG})
diff --git a/c/vendor/fmt/ChangeLog.md b/c/vendor/fmt/ChangeLog.md
index 515f9fdc1d..cab21356dd 100644
--- a/c/vendor/fmt/ChangeLog.md
+++ b/c/vendor/fmt/ChangeLog.md
@@ -1,8 +1,3 @@
-# 10.2.1 - 2024-01-03
-
-- Fixed ABI compatibility with earlier 10.x versions
- (https://github.com/fmtlib/fmt/pull/3786). Thanks @saraedum.
-
# 10.2.0 - 2024-01-01
- Added support for the `%j` specifier (the number of days) for
@@ -2046,7 +2041,7 @@
returned by `fmt::system_category()`
(https://github.com/fmtlib/fmt/issues/2274,
https://github.com/fmtlib/fmt/pull/2275). The latter is
- similar to `std::sytem_category` but correctly handles UTF-8.
+ similar to `std::system_category` but correctly handles UTF-8.
Thanks @phprus.
- Replaced `fmt::error_code` with `std::error_code` and made it
diff --git a/c/vendor/fmt/README.md b/c/vendor/fmt/README.md
index dcfb16ec22..8cb2553f4d 100644
--- a/c/vendor/fmt/README.md
+++ b/c/vendor/fmt/README.md
@@ -20,7 +20,7 @@ that help victims of the war in Ukraine: .
Q&A: ask questions on [StackOverflow with the tag
fmt](https://stackoverflow.com/questions/tagged/fmt).
-Try {fmt} in [Compiler Explorer](https://godbolt.org/z/Eq5763).
+Try {fmt} in [Compiler Explorer](https://godbolt.org/z/8Mx1EW73v).
# Features
@@ -203,43 +203,38 @@ and [ryu](https://github.com/ulfjack/ryu):
## Compile time and code bloat
-The script
-[bloat-test.py](https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py)
-from [format-benchmark](https://github.com/fmtlib/format-benchmark)
-tests compile time and code bloat for nontrivial projects. It generates
-100 translation units and uses `printf()` or its alternative five times
-in each to simulate a medium-sized project. The resulting executable
-size and compile time (Apple LLVM version 8.1.0 (clang-802.0.42), macOS
-Sierra, best of three) is shown in the following tables.
+The script [bloat-test.py][test] from [format-benchmark][bench] tests compile
+time and code bloat for nontrivial projects. It generates 100 translation units
+and uses `printf()` or its alternative five times in each to simulate a
+medium-sized project. The resulting executable size and compile time (Apple
+clang version 15.0.0 (clang-1500.1.0.2.5), macOS Sonoma, best of three) is shown
+in the following tables.
+
+[test]: https://github.com/fmtlib/format-benchmark/blob/master/bloat-test.py
+[bench]: https://github.com/fmtlib/format-benchmark
**Optimized build (-O3)**
| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
|---------------|-----------------|----------------------|--------------------|
-| printf | 2.6 | 29 | 26 |
-| printf+string | 16.4 | 29 | 26 |
-| iostreams | 31.1 | 59 | 55 |
-| {fmt} | 19.0 | 37 | 34 |
-| Boost Format | 91.9 | 226 | 203 |
-| Folly Format | 115.7 | 101 | 88 |
-
-As you can see, {fmt} has 60% less overhead in terms of resulting binary
-code size compared to iostreams and comes pretty close to `printf`.
-Boost Format and Folly Format have the largest overheads.
+| printf | 1.6 | 54 | 50 |
+| IOStreams | 25.9 | 98 | 84 |
+| fmt 83652df | 4.8 | 54 | 50 |
+| tinyformat | 29.1 | 161 | 136 |
+| Boost Format | 55.0 | 530 | 317 |
-`printf+string` is the same as `printf` but with an extra ``
-include to measure the overhead of the latter.
+{fmt} is fast to compile and is comparable to `printf` in terms of per-call
+binary size (within a rounding error on this system).
**Non-optimized build**
| Method | Compile Time, s | Executable size, KiB | Stripped size, KiB |
|---------------|-----------------|----------------------|--------------------|
-| printf | 2.2 | 33 | 30 |
-| printf+string | 16.0 | 33 | 30 |
-| iostreams | 28.3 | 56 | 52 |
-| {fmt} | 18.2 | 59 | 50 |
-| Boost Format | 54.1 | 365 | 303 |
-| Folly Format | 79.9 | 445 | 430 |
+| printf | 1.4 | 54 | 50 |
+| IOStreams | 23.4 | 92 | 68 |
+| {fmt} 83652df | 4.4 | 89 | 85 |
+| tinyformat | 24.5 | 204 | 161 |
+| Boost Format | 36.4 | 831 | 462 |
`libc`, `lib(std)c++`, and `libfmt` are all linked as shared libraries
to compare formatting function overhead only. Boost Format is a
@@ -343,7 +338,7 @@ converts to `std::print`.)
- [Quill](https://github.com/odygrd/quill): asynchronous low-latency
logging library
- [QKW](https://github.com/ravijanjam/qkw): generalizing aliasing to
- simplify navigation, and executing complex multi-line terminal
+ simplify navigation, and execute complex multi-line terminal
command sequences
- [redis-cerberus](https://github.com/HunanTV/redis-cerberus): a Redis
cluster proxy
@@ -432,7 +427,7 @@ code bloat issues (see [Benchmarks](#benchmarks)).
## FastFormat
-This is an interesting library that is fast, safe, and has positional
+This is an interesting library that is fast, safe and has positional
arguments. However, it has significant limitations, citing its author:
> Three features that have no hope of being accommodated within the
@@ -442,8 +437,8 @@ arguments. However, it has significant limitations, citing its author:
> - Octal/hexadecimal encoding
> - Runtime width/alignment specification
-It is also quite big and has a heavy dependency, STLSoft, which might be
-too restrictive for using it in some projects.
+It is also quite big and has a heavy dependency, on STLSoft, which might be
+too restrictive for use in some projects.
## Boost Spirit.Karma
@@ -486,5 +481,5 @@ To report a security issue, please disclose it at [security
advisory](https://github.com/fmtlib/fmt/security/advisories/new).
This project is maintained by a team of volunteers on a
-reasonable-effort basis. As such, please give us at least 90 days to
+reasonable-effort basis. As such, please give us at least *90* days to
work on a fix before public exposure.
diff --git a/c/vendor/fmt/include/fmt/args.h b/c/vendor/fmt/include/fmt/args.h
index ad1654bbb6..b77a2d0661 100644
--- a/c/vendor/fmt/include/fmt/args.h
+++ b/c/vendor/fmt/include/fmt/args.h
@@ -12,7 +12,7 @@
#include // std::unique_ptr
#include
-#include "core.h"
+#include "format.h" // std_string_view
FMT_BEGIN_NAMESPACE
diff --git a/c/vendor/fmt/include/fmt/base.h b/c/vendor/fmt/include/fmt/base.h
new file mode 100644
index 0000000000..bc9cfb2f70
--- /dev/null
+++ b/c/vendor/fmt/include/fmt/base.h
@@ -0,0 +1,3068 @@
+// Formatting library for C++ - the base API for char/UTF-8
+//
+// Copyright (c) 2012 - present, Victor Zverovich
+// All rights reserved.
+//
+// For the license information refer to format.h.
+
+#ifndef FMT_BASE_H_
+#define FMT_BASE_H_
+
+#include // CHAR_BIT
+#include // FILE
+#include // strlen
+
+// is also included transitively from .
+#include // std::byte
+#include // std::enable_if
+
+// The fmt library version in the form major * 10000 + minor * 100 + patch.
+#define FMT_VERSION 100202
+
+// Detect compiler versions.
+#if defined(__clang__) && !defined(__ibmxl__)
+# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
+#else
+# define FMT_CLANG_VERSION 0
+#endif
+#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
+# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+#else
+# define FMT_GCC_VERSION 0
+#endif
+#if defined(__ICL)
+# define FMT_ICC_VERSION __ICL
+#elif defined(__INTEL_COMPILER)
+# define FMT_ICC_VERSION __INTEL_COMPILER
+#else
+# define FMT_ICC_VERSION 0
+#endif
+#if defined(_MSC_VER)
+# define FMT_MSC_VERSION _MSC_VER
+#else
+# define FMT_MSC_VERSION 0
+#endif
+
+// Detect standard library versions.
+#ifdef _GLIBCXX_RELEASE
+# define FMT_GLIBCXX_RELEASE _GLIBCXX_RELEASE
+#else
+# define FMT_GLIBCXX_RELEASE 0
+#endif
+#ifdef _LIBCPP_VERSION
+# define FMT_LIBCPP_VERSION _LIBCPP_VERSION
+#else
+# define FMT_LIBCPP_VERSION 0
+#endif
+
+#ifdef _MSVC_LANG
+# define FMT_CPLUSPLUS _MSVC_LANG
+#else
+# define FMT_CPLUSPLUS __cplusplus
+#endif
+
+// Detect __has_*.
+#ifdef __has_feature
+# define FMT_HAS_FEATURE(x) __has_feature(x)
+#else
+# define FMT_HAS_FEATURE(x) 0
+#endif
+#ifdef __has_include
+# define FMT_HAS_INCLUDE(x) __has_include(x)
+#else
+# define FMT_HAS_INCLUDE(x) 0
+#endif
+#ifdef __has_cpp_attribute
+# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
+#else
+# define FMT_HAS_CPP_ATTRIBUTE(x) 0
+#endif
+
+#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
+ (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
+
+#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
+ (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
+
+// Detect C++14 relaxed constexpr.
+#ifdef FMT_USE_CONSTEXPR
+// Use the provided definition.
+#elif FMT_GCC_VERSION >= 600 && FMT_CPLUSPLUS >= 201402L
+// GCC only allows throw in constexpr since version 6:
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67371.
+# define FMT_USE_CONSTEXPR 1
+#elif FMT_ICC_VERSION
+# define FMT_USE_CONSTEXPR 0 // https://github.com/fmtlib/fmt/issues/1628
+#elif FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912
+# define FMT_USE_CONSTEXPR 1
+#else
+# define FMT_USE_CONSTEXPR 0
+#endif
+#if FMT_USE_CONSTEXPR
+# define FMT_CONSTEXPR constexpr
+#else
+# define FMT_CONSTEXPR
+#endif
+
+// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated.
+#if !defined(__cpp_lib_is_constant_evaluated)
+# define FMT_USE_CONSTEVAL 0
+#elif FMT_CPLUSPLUS < 201709L
+# define FMT_USE_CONSTEVAL 0
+#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10
+# define FMT_USE_CONSTEVAL 0
+#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000
+# define FMT_USE_CONSTEVAL 0
+#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L
+# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14.
+#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929
+# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10.
+#elif defined(__cpp_consteval)
+# define FMT_USE_CONSTEVAL 1
+#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101
+# define FMT_USE_CONSTEVAL 1
+#else
+# define FMT_USE_CONSTEVAL 0
+#endif
+#if FMT_USE_CONSTEVAL
+# define FMT_CONSTEVAL consteval
+# define FMT_CONSTEXPR20 constexpr
+#else
+# define FMT_CONSTEVAL
+# define FMT_CONSTEXPR20
+#endif
+
+#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
+// Use the provided definition.
+#elif defined(__NVCOMPILER)
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
+#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
+#elif defined(__cpp_nontype_template_args) && \
+ __cpp_nontype_template_args >= 201911L
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
+#else
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
+#endif
+
+// Check if exceptions are disabled.
+#ifdef FMT_EXCEPTIONS
+// Use the provided definition.
+#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
+# define FMT_EXCEPTIONS 0
+#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
+# define FMT_EXCEPTIONS 0
+#else
+# define FMT_EXCEPTIONS 1
+#endif
+#if FMT_EXCEPTIONS
+# define FMT_TRY try
+# define FMT_CATCH(x) catch (x)
+#else
+# define FMT_TRY if (true)
+# define FMT_CATCH(x) if (false)
+#endif
+
+#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
+# define FMT_FALLTHROUGH [[fallthrough]]
+#elif defined(__clang__)
+# define FMT_FALLTHROUGH [[clang::fallthrough]]
+#elif FMT_GCC_VERSION >= 700 && \
+ (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
+# define FMT_FALLTHROUGH [[gnu::fallthrough]]
+#else
+# define FMT_FALLTHROUGH
+#endif
+
+// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings.
+#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && FMT_EXCEPTIONS && !FMT_MSC_VERSION && \
+ !defined(__NVCC__)
+# define FMT_NORETURN [[noreturn]]
+#else
+# define FMT_NORETURN
+#endif
+
+#ifndef FMT_NODISCARD
+# if FMT_HAS_CPP17_ATTRIBUTE(nodiscard)
+# define FMT_NODISCARD [[nodiscard]]
+# else
+# define FMT_NODISCARD
+# endif
+#endif
+
+#ifdef FMT_DEPRECATED
+// Use the provided definition.
+#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
+# define FMT_DEPRECATED [[deprecated]]
+#else
+# define FMT_DEPRECATED /* deprecated */
+#endif
+
+#ifdef FMT_INLINE
+// Use the provided definition.
+#elif FMT_GCC_VERSION || FMT_CLANG_VERSION
+# define FMT_ALWAYS_INLINE inline __attribute__((always_inline))
+#else
+# define FMT_ALWAYS_INLINE inline
+#endif
+// A version of FMT_INLINE to prevent code bloat in debug mode.
+#ifdef NDEBUG
+# define FMT_INLINE FMT_ALWAYS_INLINE
+#else
+# define FMT_INLINE inline
+#endif
+
+#if FMT_GCC_VERSION || FMT_CLANG_VERSION
+# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
+#else
+# define FMT_VISIBILITY(value)
+#endif
+
+#ifndef FMT_GCC_PRAGMA
+// Workaround a _Pragma bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59884
+// and an nvhpc warning: https://github.com/fmtlib/fmt/pull/2582.
+# if FMT_GCC_VERSION >= 504 && !defined(__NVCOMPILER)
+# define FMT_GCC_PRAGMA(arg) _Pragma(arg)
+# else
+# define FMT_GCC_PRAGMA(arg)
+# endif
+#endif
+
+// GCC < 5 requires this-> in decltype.
+#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
+# define FMT_DECLTYPE_THIS this->
+#else
+# define FMT_DECLTYPE_THIS
+#endif
+
+#if FMT_MSC_VERSION
+# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__))
+# define FMT_UNCHECKED_ITERATOR(It) \
+ using _Unchecked_type = It // Mark iterator as checked.
+#else
+# define FMT_MSC_WARNING(...)
+# define FMT_UNCHECKED_ITERATOR(It) using unchecked_type = It
+#endif
+
+#ifndef FMT_BEGIN_NAMESPACE
+# define FMT_BEGIN_NAMESPACE \
+ namespace fmt { \
+ inline namespace v10 {
+# define FMT_END_NAMESPACE \
+ } \
+ }
+#endif
+
+#ifndef FMT_EXPORT
+# define FMT_EXPORT
+# define FMT_BEGIN_EXPORT
+# define FMT_END_EXPORT
+#endif
+
+#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
+# if defined(FMT_LIB_EXPORT)
+# define FMT_API __declspec(dllexport)
+# elif defined(FMT_SHARED)
+# define FMT_API __declspec(dllimport)
+# endif
+#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
+# define FMT_API FMT_VISIBILITY("default")
+#endif
+#ifndef FMT_API
+# define FMT_API
+#endif
+
+#ifndef FMT_UNICODE
+# define FMT_UNICODE !FMT_MSC_VERSION
+#endif
+
+#define FMT_FWD(...) static_cast(__VA_ARGS__)
+
+// Enable minimal optimizations for more compact code in debug mode.
+FMT_GCC_PRAGMA("GCC push_options")
+#if !defined(__OPTIMIZE__) && !defined(__CUDACC__)
+FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
+#endif
+
+FMT_BEGIN_NAMESPACE
+
+// Implementations of enable_if_t and other metafunctions for older systems.
+template
+using enable_if_t = typename std::enable_if::type;
+template
+using conditional_t = typename std::conditional::type;
+template using bool_constant = std::integral_constant;
+template
+using remove_reference_t = typename std::remove_reference::type;
+template
+using remove_const_t = typename std::remove_const::type;
+template
+using remove_cvref_t = typename std::remove_cv>::type;
+template struct type_identity {
+ using type = T;
+};
+template using type_identity_t = typename type_identity::type;
+template
+using make_unsigned_t = typename std::make_unsigned::type;
+template
+using underlying_t = typename std::underlying_type::type;
+
+#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
+// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
+template struct void_t_impl {
+ using type = void;
+};
+template using void_t = typename void_t_impl::type;
+#else
+template using void_t = void;
+#endif
+
+struct monostate {
+ constexpr monostate() {}
+};
+
+// An enable_if helper to be used in template parameters which results in much
+// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
+// to workaround a bug in MSVC 2019 (see #1140 and #1186).
+#ifdef FMT_DOC
+# define FMT_ENABLE_IF(...)
+#else
+# define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0
+#endif
+
+// This is defined in base.h instead of format.h to avoid injecting in std.
+// It is a template to avoid undesirable implicit conversions to std::byte.
+#ifdef __cpp_lib_byte
+template ::value)>
+inline auto format_as(T b) -> unsigned char {
+ return static_cast(b);
+}
+#endif
+
+namespace detail {
+// Suppresses "unused variable" warnings with the method described in
+// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
+// (void)var does not work on many Intel compilers.
+template FMT_CONSTEXPR void ignore_unused(const T&...) {}
+
+constexpr auto is_constant_evaluated(bool default_value = false) noexcept
+ -> bool {
+// Workaround for incompatibility between libstdc++ consteval-based
+// std::is_constant_evaluated() implementation and clang-14:
+// https://github.com/fmtlib/fmt/issues/3247.
+#if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \
+ (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500)
+ ignore_unused(default_value);
+ return __builtin_is_constant_evaluated();
+#elif defined(__cpp_lib_is_constant_evaluated)
+ ignore_unused(default_value);
+ return std::is_constant_evaluated();
+#else
+ return default_value;
+#endif
+}
+
+// Suppresses "conditional expression is constant" warnings.
+template constexpr auto const_check(T value) -> T { return value; }
+
+FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
+ const char* message);
+
+#ifndef FMT_ASSERT
+# ifdef NDEBUG
+// FMT_ASSERT is not empty to avoid -Wempty-body.
+# define FMT_ASSERT(condition, message) \
+ fmt::detail::ignore_unused((condition), (message))
+# else
+# define FMT_ASSERT(condition, message) \
+ ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
+ ? (void)0 \
+ : fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
+# endif
+#endif
+
+#ifdef FMT_USE_INT128
+// Do nothing.
+#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \
+ !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
+# define FMT_USE_INT128 1
+using int128_opt = __int128_t; // An optional native 128-bit integer.
+using uint128_opt = __uint128_t;
+template inline auto convert_for_visit(T value) -> T {
+ return value;
+}
+#else
+# define FMT_USE_INT128 0
+#endif
+#if !FMT_USE_INT128
+enum class int128_opt {};
+enum class uint128_opt {};
+// Reduce template instantiations.
+template auto convert_for_visit(T) -> monostate { return {}; }
+#endif
+
+// Casts a nonnegative integer to unsigned.
+template
+FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t {
+ FMT_ASSERT(std::is_unsigned::value || value >= 0, "negative value");
+ return static_cast>(value);
+}
+
+// A heuristic to detect std::string and std::[experimental::]string_view.
+// It is mainly used to avoid dependency on <[experimental/]string_view>.
+template
+struct is_std_string_like : std::false_type {};
+template
+struct is_std_string_like().find_first_of(
+ typename T::value_type(), 0))>>
+ : std::true_type {};
+
+FMT_CONSTEXPR inline auto is_utf8() -> bool {
+ FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char section[] = "\u00A7";
+ // Avoid an MSVC sign extension bug: https://github.com/fmtlib/fmt/pull/2297.
+ using uchar = unsigned char;
+ return FMT_UNICODE || (sizeof(section) == 3 && uchar(section[0]) == 0xC2 &&
+ uchar(section[1]) == 0xA7);
+}
+
+template FMT_CONSTEXPR auto length(const Char* s) -> size_t {
+ size_t len = 0;
+ while (*s++) ++len;
+ return len;
+}
+
+template
+FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, std::size_t n)
+ -> int {
+ for (; n != 0; ++s1, ++s2, --n) {
+ if (*s1 < *s2) return -1;
+ if (*s1 > *s2) return 1;
+ }
+ return 0;
+}
+
+template
+struct is_back_insert_iterator : std::false_type {};
+template
+struct is_back_insert_iterator<
+ It,
+ bool_constant())),
+ It>::value>> : std::true_type {};
+
+// Extracts a reference to the container from *insert_iterator.
+template
+inline auto get_container(OutputIt it) -> typename OutputIt::container_type& {
+ struct accessor : OutputIt {
+ accessor(OutputIt base) : OutputIt(base) {}
+ using OutputIt::container;
+ };
+ return *accessor(it).container;
+}
+} // namespace detail
+
+// Checks whether T is a container with contiguous storage.
+template struct is_contiguous : std::false_type {};
+
+/**
+ An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
+ subset of the API. ``fmt::basic_string_view`` is used for format strings even
+ if ``std::string_view`` is available to prevent issues when a library is
+ compiled with a different ``-std`` option than the client code (which is not
+ recommended).
+ */
+FMT_EXPORT
+template class basic_string_view {
+ private:
+ const Char* data_;
+ size_t size_;
+
+ public:
+ using value_type = Char;
+ using iterator = const Char*;
+
+ constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {}
+
+ /** Constructs a string reference object from a C string and a size. */
+ constexpr basic_string_view(const Char* s, size_t count) noexcept
+ : data_(s), size_(count) {}
+
+ constexpr basic_string_view(std::nullptr_t) = delete;
+
+ /**
+ Constructs a string reference object from a C string.
+ */
+ FMT_CONSTEXPR20
+ basic_string_view(const Char* s)
+ : data_(s),
+ size_(detail::const_check(std::is_same::value &&
+ !detail::is_constant_evaluated(false))
+ ? strlen(reinterpret_cast(s))
+ : detail::length(s)) {}
+
+ /**
+ Constructs a string reference from a ``std::basic_string`` or a
+ ``std::basic_string_view`` object.
+ */
+ template ::value&& std::is_same<
+ typename S::value_type, Char>::value)>
+ FMT_CONSTEXPR basic_string_view(const S& s) noexcept
+ : data_(s.data()), size_(s.size()) {}
+
+ /** Returns a pointer to the string data. */
+ constexpr auto data() const noexcept -> const Char* { return data_; }
+
+ /** Returns the string size. */
+ constexpr auto size() const noexcept -> size_t { return size_; }
+
+ constexpr auto begin() const noexcept -> iterator { return data_; }
+ constexpr auto end() const noexcept -> iterator { return data_ + size_; }
+
+ constexpr auto operator[](size_t pos) const noexcept -> const Char& {
+ return data_[pos];
+ }
+
+ FMT_CONSTEXPR void remove_prefix(size_t n) noexcept {
+ data_ += n;
+ size_ -= n;
+ }
+
+ FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept
+ -> bool {
+ return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0;
+ }
+ FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool {
+ return size_ >= 1 && *data_ == c;
+ }
+ FMT_CONSTEXPR auto starts_with(const Char* s) const -> bool {
+ return starts_with(basic_string_view(s));
+ }
+
+ // Lexicographically compare this string reference to other.
+ FMT_CONSTEXPR auto compare(basic_string_view other) const -> int {
+ size_t str_size = size_ < other.size_ ? size_ : other.size_;
+ int result = detail::compare(data_, other.data_, str_size);
+ if (result == 0)
+ result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
+ return result;
+ }
+
+ FMT_CONSTEXPR friend auto operator==(basic_string_view lhs,
+ basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) == 0;
+ }
+ friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) != 0;
+ }
+ friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) < 0;
+ }
+ friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) <= 0;
+ }
+ friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) > 0;
+ }
+ friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) >= 0;
+ }
+};
+
+FMT_EXPORT
+using string_view = basic_string_view;
+
+/** Specifies if ``T`` is a character type. Can be specialized by users. */
+FMT_EXPORT
+template struct is_char : std::false_type {};
+template <> struct is_char : std::true_type {};
+
+namespace detail {
+
+// Constructs fmt::basic_string_view from types implicitly convertible
+// to it, deducing Char. Explicitly convertible types such as the ones returned
+// from FMT_STRING are intentionally excluded.
+template ::value)>
+auto to_string_view(const Char* s) -> basic_string_view {
+ return s;
+}
+template ::value)>
+auto to_string_view(const T& s) -> basic_string_view {
+ return s;
+}
+template
+constexpr auto to_string_view(basic_string_view s)
+ -> basic_string_view {
+ return s;
+}
+
+template
+struct has_to_string_view : std::false_type {};
+// detail:: is intentional since to_string_view is not an extension point.
+template
+struct has_to_string_view<
+ T, void_t()))>>
+ : std::true_type {};
+
+template struct string_literal {
+ static constexpr Char value[sizeof...(C)] = {C...};
+ constexpr operator basic_string_view() const {
+ return {value, sizeof...(C)};
+ }
+};
+#if FMT_CPLUSPLUS < 201703L
+template
+constexpr Char string_literal::value[sizeof...(C)];
+#endif
+
+enum class type {
+ none_type,
+ // Integer types should go first,
+ int_type,
+ uint_type,
+ long_long_type,
+ ulong_long_type,
+ int128_type,
+ uint128_type,
+ bool_type,
+ char_type,
+ last_integer_type = char_type,
+ // followed by floating-point types.
+ float_type,
+ double_type,
+ long_double_type,
+ last_numeric_type = long_double_type,
+ cstring_type,
+ string_type,
+ pointer_type,
+ custom_type
+};
+
+// Maps core type T to the corresponding type enum constant.
+template
+struct type_constant : std::integral_constant {};
+
+#define FMT_TYPE_CONSTANT(Type, constant) \
+ template \
+ struct type_constant \
+ : std::integral_constant {}
+
+FMT_TYPE_CONSTANT(int, int_type);
+FMT_TYPE_CONSTANT(unsigned, uint_type);
+FMT_TYPE_CONSTANT(long long, long_long_type);
+FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type);
+FMT_TYPE_CONSTANT(int128_opt, int128_type);
+FMT_TYPE_CONSTANT(uint128_opt, uint128_type);
+FMT_TYPE_CONSTANT(bool, bool_type);
+FMT_TYPE_CONSTANT(Char, char_type);
+FMT_TYPE_CONSTANT(float, float_type);
+FMT_TYPE_CONSTANT(double, double_type);
+FMT_TYPE_CONSTANT(long double, long_double_type);
+FMT_TYPE_CONSTANT(const Char*, cstring_type);
+FMT_TYPE_CONSTANT(basic_string_view, string_type);
+FMT_TYPE_CONSTANT(const void*, pointer_type);
+
+constexpr auto is_integral_type(type t) -> bool {
+ return t > type::none_type && t <= type::last_integer_type;
+}
+constexpr auto is_arithmetic_type(type t) -> bool {
+ return t > type::none_type && t <= type::last_numeric_type;
+}
+
+constexpr auto set(type rhs) -> int { return 1 << static_cast(rhs); }
+constexpr auto in(type t, int set) -> bool {
+ return ((set >> static_cast(t)) & 1) != 0;
+}
+
+// Bitsets of types.
+enum {
+ sint_set =
+ set(type::int_type) | set(type::long_long_type) | set(type::int128_type),
+ uint_set = set(type::uint_type) | set(type::ulong_long_type) |
+ set(type::uint128_type),
+ bool_set = set(type::bool_type),
+ char_set = set(type::char_type),
+ float_set = set(type::float_type) | set(type::double_type) |
+ set(type::long_double_type),
+ string_set = set(type::string_type),
+ cstring_set = set(type::cstring_type),
+ pointer_set = set(type::pointer_type)
+};
+} // namespace detail
+
+/**
+ Reports a format error at compile time or, via a ``format_error`` exception,
+ at runtime.
+ */
+// This function is intentionally not constexpr to give a compile-time error.
+FMT_NORETURN FMT_API void report_error(const char* message);
+
+FMT_DEPRECATED FMT_NORETURN inline void throw_format_error(
+ const char* message) {
+ report_error(message);
+}
+
+/** String's character (code unit) type. */
+template ()))>
+using char_t = typename V::value_type;
+
+/**
+ \rst
+ Parsing context consisting of a format string range being parsed and an
+ argument counter for automatic indexing.
+ You can use the ``format_parse_context`` type alias for ``char`` instead.
+ \endrst
+ */
+FMT_EXPORT
+template class basic_format_parse_context {
+ private:
+ basic_string_view format_str_;
+ int next_arg_id_;
+
+ FMT_CONSTEXPR void do_check_arg_id(int id);
+
+ public:
+ using char_type = Char;
+ using iterator = const Char*;
+
+ explicit constexpr basic_format_parse_context(
+ basic_string_view format_str, int next_arg_id = 0)
+ : format_str_(format_str), next_arg_id_(next_arg_id) {}
+
+ /**
+ Returns an iterator to the beginning of the format string range being
+ parsed.
+ */
+ constexpr auto begin() const noexcept -> iterator {
+ return format_str_.begin();
+ }
+
+ /**
+ Returns an iterator past the end of the format string range being parsed.
+ */
+ constexpr auto end() const noexcept -> iterator { return format_str_.end(); }
+
+ /** Advances the begin iterator to ``it``. */
+ FMT_CONSTEXPR void advance_to(iterator it) {
+ format_str_.remove_prefix(detail::to_unsigned(it - begin()));
+ }
+
+ /**
+ Reports an error if using the manual argument indexing; otherwise returns
+ the next argument index and switches to the automatic indexing.
+ */
+ FMT_CONSTEXPR auto next_arg_id() -> int {
+ if (next_arg_id_ < 0) {
+ report_error("cannot switch from manual to automatic argument indexing");
+ return 0;
+ }
+ int id = next_arg_id_++;
+ do_check_arg_id(id);
+ return id;
+ }
+
+ /**
+ Reports an error if using the automatic argument indexing; otherwise
+ switches to the manual indexing.
+ */
+ FMT_CONSTEXPR void check_arg_id(int id) {
+ if (next_arg_id_ > 0) {
+ report_error("cannot switch from automatic to manual argument indexing");
+ return;
+ }
+ next_arg_id_ = -1;
+ do_check_arg_id(id);
+ }
+ FMT_CONSTEXPR void check_arg_id(basic_string_view) {
+ next_arg_id_ = -1;
+ }
+ FMT_CONSTEXPR void check_dynamic_spec(int arg_id);
+};
+
+FMT_EXPORT
+using format_parse_context = basic_format_parse_context;
+
+namespace detail {
+// A parse context with extra data used only in compile-time checks.
+template
+class compile_parse_context : public basic_format_parse_context {
+ private:
+ int num_args_;
+ const type* types_;
+ using base = basic_format_parse_context;
+
+ public:
+ explicit FMT_CONSTEXPR compile_parse_context(
+ basic_string_view format_str, int num_args, const type* types,
+ int next_arg_id = 0)
+ : base(format_str, next_arg_id), num_args_(num_args), types_(types) {}
+
+ constexpr auto num_args() const -> int { return num_args_; }
+ constexpr auto arg_type(int id) const -> type { return types_[id]; }
+
+ FMT_CONSTEXPR auto next_arg_id() -> int {
+ int id = base::next_arg_id();
+ if (id >= num_args_) report_error("argument not found");
+ return id;
+ }
+
+ FMT_CONSTEXPR void check_arg_id(int id) {
+ base::check_arg_id(id);
+ if (id >= num_args_) report_error("argument not found");
+ }
+ using base::check_arg_id;
+
+ FMT_CONSTEXPR void check_dynamic_spec(int arg_id) {
+ detail::ignore_unused(arg_id);
+ if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id]))
+ report_error("width/precision is not integer");
+ }
+};
+
+/**
+ \rst
+ A contiguous memory buffer with an optional growing ability. It is an internal
+ class and shouldn't be used directly, only via `~fmt::basic_memory_buffer`.
+ \endrst
+ */
+template class buffer {
+ private:
+ T* ptr_;
+ size_t size_;
+ size_t capacity_;
+
+ using grow_fun = void (*)(buffer& buf, size_t capacity);
+ grow_fun grow_;
+
+ protected:
+ // Don't initialize ptr_ since it is not accessed to save a few cycles.
+ FMT_MSC_WARNING(suppress : 26495)
+ FMT_CONSTEXPR20 buffer(grow_fun grow, size_t sz) noexcept
+ : size_(sz), capacity_(sz), grow_(grow) {}
+
+ constexpr buffer(grow_fun grow, T* p = nullptr, size_t sz = 0,
+ size_t cap = 0) noexcept
+ : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {}
+
+ FMT_CONSTEXPR20 ~buffer() = default;
+ buffer(buffer&&) = default;
+
+ /** Sets the buffer data and capacity. */
+ FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
+ ptr_ = buf_data;
+ capacity_ = buf_capacity;
+ }
+
+ public:
+ using value_type = T;
+ using const_reference = const T&;
+
+ buffer(const buffer&) = delete;
+ void operator=(const buffer&) = delete;
+
+ auto begin() noexcept -> T* { return ptr_; }
+ auto end() noexcept -> T* { return ptr_ + size_; }
+
+ auto begin() const noexcept -> const T* { return ptr_; }
+ auto end() const noexcept -> const T* { return ptr_ + size_; }
+
+ /** Returns the size of this buffer. */
+ constexpr auto size() const noexcept -> size_t { return size_; }
+
+ /** Returns the capacity of this buffer. */
+ constexpr auto capacity() const noexcept -> size_t { return capacity_; }
+
+ /** Returns a pointer to the buffer data (not null-terminated). */
+ FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
+ FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }
+
+ /** Clears this buffer. */
+ void clear() { size_ = 0; }
+
+ // Tries resizing the buffer to contain *count* elements. If T is a POD type
+ // the new elements may not be initialized.
+ FMT_CONSTEXPR void try_resize(size_t count) {
+ try_reserve(count);
+ size_ = count <= capacity_ ? count : capacity_;
+ }
+
+ // Tries increasing the buffer capacity to *new_capacity*. It can increase the
+ // capacity by a smaller amount than requested but guarantees there is space
+ // for at least one additional element either by increasing the capacity or by
+ // flushing the buffer if it is full.
+ FMT_CONSTEXPR void try_reserve(size_t new_capacity) {
+ if (new_capacity > capacity_) grow_(*this, new_capacity);
+ }
+
+ FMT_CONSTEXPR void push_back(const T& value) {
+ try_reserve(size_ + 1);
+ ptr_[size_++] = value;
+ }
+
+ /** Appends data to the end of the buffer. */
+ template void append(const U* begin, const U* end) {
+ while (begin != end) {
+ auto count = to_unsigned(end - begin);
+ try_reserve(size_ + count);
+ auto free_cap = capacity_ - size_;
+ if (free_cap < count) count = free_cap;
+ if (std::is_same::value) {
+ memcpy(ptr_ + size_, begin, count * sizeof(T));
+ } else {
+ T* out = ptr_ + size_;
+ for (size_t i = 0; i < count; ++i) out[i] = begin[i];
+ }
+ size_ += count;
+ begin += count;
+ }
+ }
+
+ template FMT_CONSTEXPR auto operator[](Idx index) -> T& {
+ return ptr_[index];
+ }
+ template
+ FMT_CONSTEXPR auto operator[](Idx index) const -> const T& {
+ return ptr_[index];
+ }
+};
+
+struct buffer_traits {
+ explicit buffer_traits(size_t) {}
+ auto count() const -> size_t { return 0; }
+ auto limit(size_t size) -> size_t { return size; }
+};
+
+class fixed_buffer_traits {
+ private:
+ size_t count_ = 0;
+ size_t limit_;
+
+ public:
+ explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
+ auto count() const -> size_t { return count_; }
+ auto limit(size_t size) -> size_t {
+ size_t n = limit_ > count_ ? limit_ - count_ : 0;
+ count_ += size;
+ return size < n ? size : n;
+ }
+};
+
+// A buffer that writes to an output iterator when flushed.
+template
+class iterator_buffer : public Traits, public buffer {
+ private:
+ OutputIt out_;
+ enum { buffer_size = 256 };
+ T data_[buffer_size];
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t) {
+ if (buf.size() == buffer_size) static_cast(buf).flush();
+ }
+
+ void flush() {
+ auto size = this->size();
+ this->clear();
+ const T* begin = data_;
+ const T* end = begin + this->limit(size);
+ while (begin != end) *out_++ = *begin++;
+ }
+
+ public:
+ explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
+ : Traits(n), buffer(grow, data_, 0, buffer_size), out_(out) {}
+ iterator_buffer(iterator_buffer&& other) noexcept
+ : Traits(other),
+ buffer(grow, data_, 0, buffer_size),
+ out_(other.out_) {}
+ ~iterator_buffer() {
+ // Don't crash if flush fails during unwinding.
+ FMT_TRY { flush(); }
+ FMT_CATCH(...) {}
+ }
+
+ auto out() -> OutputIt {
+ flush();
+ return out_;
+ }
+ auto count() const -> size_t { return Traits::count() + this->size(); }
+};
+
+template
+class iterator_buffer : public fixed_buffer_traits,
+ public buffer {
+ private:
+ T* out_;
+ enum { buffer_size = 256 };
+ T data_[buffer_size];
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t) {
+ if (buf.size() == buf.capacity())
+ static_cast(buf).flush();
+ }
+
+ void flush() {
+ size_t n = this->limit(this->size());
+ if (this->data() == out_) {
+ out_ += n;
+ this->set(data_, buffer_size);
+ }
+ this->clear();
+ }
+
+ public:
+ explicit iterator_buffer(T* out, size_t n = buffer_size)
+ : fixed_buffer_traits(n), buffer(grow, out, 0, n), out_(out) {}
+ iterator_buffer(iterator_buffer&& other) noexcept
+ : fixed_buffer_traits(other),
+ buffer(static_cast(other)),
+ out_(other.out_) {
+ if (this->data() != out_) {
+ this->set(data_, buffer_size);
+ this->clear();
+ }
+ }
+ ~iterator_buffer() { flush(); }
+
+ auto out() -> T* {
+ flush();
+ return out_;
+ }
+ auto count() const -> size_t {
+ return fixed_buffer_traits::count() + this->size();
+ }
+};
+
+template class iterator_buffer : public buffer {
+ public:
+ explicit iterator_buffer(T* out, size_t = 0)
+ : buffer([](buffer&, size_t) {}, out, 0, ~size_t()) {}
+
+ auto out() -> T* { return &*this->end(); }
+};
+
+// A buffer that writes to a container with the contiguous storage.
+template
+class iterator_buffer<
+ OutputIt,
+ enable_if_t::value &&
+ is_contiguous::value,
+ typename OutputIt::container_type::value_type>>
+ : public buffer {
+ private:
+ using container_type = typename OutputIt::container_type;
+ using value_type = typename container_type::value_type;
+ container_type& container_;
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t capacity) {
+ auto& self = static_cast(buf);
+ self.container_.resize(capacity);
+ self.set(&self.container_[0], capacity);
+ }
+
+ public:
+ explicit iterator_buffer(container_type& c)
+ : buffer(grow, c.size()), container_(c) {}
+ explicit iterator_buffer(OutputIt out, size_t = 0)
+ : iterator_buffer(get_container(out)) {}
+
+ auto out() -> OutputIt { return back_inserter(container_); }
+};
+
+// A buffer that counts the number of code units written discarding the output.
+template class counting_buffer : public buffer {
+ private:
+ enum { buffer_size = 256 };
+ T data_[buffer_size];
+ size_t count_ = 0;
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t) {
+ if (buf.size() != buffer_size) return;
+ static_cast(buf).count_ += buf.size();
+ buf.clear();
+ }
+
+ public:
+ counting_buffer() : buffer(grow, data_, 0, buffer_size) {}
+
+ auto count() -> size_t { return count_ + this->size(); }
+};
+} // namespace detail
+
+template
+FMT_CONSTEXPR void basic_format_parse_context::do_check_arg_id(int id) {
+ // Argument id is only checked at compile-time during parsing because
+ // formatting has its own validation.
+ if (detail::is_constant_evaluated() &&
+ (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
+ using context = detail::compile_parse_context;
+ if (id >= static_cast(this)->num_args())
+ report_error("argument not found");
+ }
+}
+
+template
+FMT_CONSTEXPR void basic_format_parse_context::check_dynamic_spec(
+ int arg_id) {
+ if (detail::is_constant_evaluated() &&
+ (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
+ using context = detail::compile_parse_context;
+ static_cast(this)->check_dynamic_spec(arg_id);
+ }
+}
+
+FMT_EXPORT template class basic_format_arg;
+FMT_EXPORT template class basic_format_args;
+FMT_EXPORT template class dynamic_format_arg_store;
+
+// A formatter for objects of type T.
+FMT_EXPORT
+template
+struct formatter {
+ // A deleted default constructor indicates a disabled formatter.
+ formatter() = delete;
+};
+
+// Specifies if T has an enabled formatter specialization. A type can be
+// formattable even if it doesn't have a formatter e.g. via a conversion.
+template
+using has_formatter =
+ std::is_constructible>;
+
+// An output iterator that appends to a buffer. It is used instead of
+// back_insert_iterator to reduce symbol sizes and avoid dependency.
+template class basic_appender {
+ private:
+ detail::buffer* buffer_;
+
+ friend auto get_container(basic_appender app) -> detail::buffer& {
+ return *app.buffer_;
+ }
+
+ public:
+ using iterator_category = int;
+ using value_type = T;
+ using difference_type = ptrdiff_t;
+ using pointer = T*;
+ using reference = T&;
+ FMT_UNCHECKED_ITERATOR(basic_appender);
+
+ FMT_CONSTEXPR basic_appender(detail::buffer& buf) : buffer_(&buf) {}
+
+ auto operator=(T c) -> basic_appender& {
+ buffer_->push_back(c);
+ return *this;
+ }
+ auto operator*() -> basic_appender& { return *this; }
+ auto operator++() -> basic_appender& { return *this; }
+ auto operator++(int) -> basic_appender { return *this; }
+};
+
+using appender = basic_appender;
+
+namespace detail {
+
+template
+struct locking : std::true_type {};
+template
+struct locking>::nonlocking>>
+ : std::false_type {};
+
+template FMT_CONSTEXPR inline auto is_locking() -> bool {
+ return locking::value;
+}
+template
+FMT_CONSTEXPR inline auto is_locking() -> bool {
+ return locking::value || is_locking();
+}
+
+// An optimized version of std::copy with the output value type (T).
+template
+auto copy(InputIt begin, InputIt end, appender out) -> appender {
+ get_container(out).append(begin, end);
+ return out;
+}
+
+template ::value)>
+auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
+ get_container(out).append(begin, end);
+ return out;
+}
+
+template ::value)>
+FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
+ while (begin != end) *out++ = static_cast(*begin++);
+ return out;
+}
+
+template
+FMT_CONSTEXPR auto copy(const T* begin, const T* end, T* out) -> T* {
+ if (is_constant_evaluated()) return copy(begin, end, out);
+ auto size = to_unsigned(end - begin);
+ if (size > 0) memcpy(out, begin, size * sizeof(T));
+ return out + size;
+}
+
+template
+FMT_CONSTEXPR auto copy(basic_string_view s, OutputIt out) -> OutputIt {
+ return copy(s.begin(), s.end(), out);
+}
+
+template
+constexpr auto has_const_formatter_impl(T*)
+ -> decltype(typename Context::template formatter_type().format(
+ std::declval(), std::declval()),
+ true) {
+ return true;
+}
+template
+constexpr auto has_const_formatter_impl(...) -> bool {
+ return false;
+}
+template
+constexpr auto has_const_formatter() -> bool {
+ return has_const_formatter_impl(static_cast(nullptr));
+}
+
+// Maps an output iterator to a buffer.
+template
+auto get_buffer(OutputIt out) -> iterator_buffer {
+ return iterator_buffer(out);
+}
+template auto get_buffer(basic_appender out) -> buffer& {
+ return get_container(out);
+}
+
+template
+auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) {
+ return buf.out();
+}
+template
+auto get_iterator(buffer&, OutputIt out) -> OutputIt {
+ return out;
+}
+
+struct view {};
+
+template struct named_arg : view {
+ const Char* name;
+ const T& value;
+ named_arg(const Char* n, const T& v) : name(n), value(v) {}
+};
+
+template struct named_arg_info {
+ const Char* name;
+ int id;
+};
+
+template struct is_named_arg : std::false_type {};
+template struct is_statically_named_arg : std::false_type {};
+
+template
+struct is_named_arg> : std::true_type {};
+
+template constexpr auto count() -> size_t { return B ? 1 : 0; }
+template constexpr auto count() -> size_t {
+ return (B1 ? 1 : 0) + count();
+}
+
+template constexpr auto count_named_args() -> size_t {
+ return count::value...>();
+}
+
+template
+constexpr auto count_statically_named_args() -> size_t {
+ return count::value...>();
+}
+
+struct unformattable {};
+struct unformattable_char : unformattable {};
+struct unformattable_pointer : unformattable {};
+
+template struct string_value {
+ const Char* data;
+ size_t size;
+};
+
+template struct named_arg_value {
+ const named_arg_info* data;
+ size_t size;
+};
+
+template struct custom_value {
+ using parse_context = typename Context::parse_context_type;
+ void* value;
+ void (*format)(void* arg, parse_context& parse_ctx, Context& ctx);
+};
+
+// A formatting argument value.
+template class value {
+ public:
+ using char_type = typename Context::char_type;
+
+ union {
+ monostate no_value;
+ int int_value;
+ unsigned uint_value;
+ long long long_long_value;
+ unsigned long long ulong_long_value;
+ int128_opt int128_value;
+ uint128_opt uint128_value;
+ bool bool_value;
+ char_type char_value;
+ float float_value;
+ double double_value;
+ long double long_double_value;
+ const void* pointer;
+ string_value string;
+ custom_value custom;
+ named_arg_value named_args;
+ };
+
+ constexpr FMT_ALWAYS_INLINE value() : no_value() {}
+ constexpr FMT_ALWAYS_INLINE value(int val) : int_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(unsigned val) : uint_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(long long val) : long_long_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(unsigned long long val)
+ : ulong_long_value(val) {}
+ FMT_ALWAYS_INLINE value(int128_opt val) : int128_value(val) {}
+ FMT_ALWAYS_INLINE value(uint128_opt val) : uint128_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(float val) : float_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(double val) : double_value(val) {}
+ FMT_ALWAYS_INLINE value(long double val) : long_double_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(bool val) : bool_value(val) {}
+ constexpr FMT_ALWAYS_INLINE value(char_type val) : char_value(val) {}
+ FMT_CONSTEXPR FMT_ALWAYS_INLINE value(const char_type* val) {
+ string.data = val;
+ if (is_constant_evaluated()) string.size = {};
+ }
+ FMT_CONSTEXPR FMT_ALWAYS_INLINE value(basic_string_view val) {
+ string.data = val.data();
+ string.size = val.size();
+ }
+ FMT_ALWAYS_INLINE value(const void* val) : pointer(val) {}
+ FMT_ALWAYS_INLINE value(const named_arg_info* args, size_t size)
+ : named_args{args, size} {}
+
+ template FMT_CONSTEXPR20 FMT_ALWAYS_INLINE value(T& val) {
+ using value_type = remove_const_t;
+ // T may overload operator& e.g. std::vector::reference in libc++.
+#if defined(__cpp_if_constexpr)
+ if constexpr (std::is_same::value)
+ custom.value = const_cast(&val);
+#endif
+ if (!is_constant_evaluated())
+ custom.value = const_cast(&reinterpret_cast(val));
+ // Get the formatter type through the context to allow different contexts
+ // have different extension points, e.g. `formatter` for `format` and
+ // `printf_formatter` for `printf`.
+ custom.format = format_custom_arg<
+ value_type, typename Context::template formatter_type>;
+ }
+ value(unformattable);
+ value(unformattable_char);
+ value(unformattable_pointer);
+
+ private:
+ // Formats an argument of a custom type, such as a user-defined class.
+ template
+ static void format_custom_arg(void* arg,
+ typename Context::parse_context_type& parse_ctx,
+ Context& ctx) {
+ auto f = Formatter();
+ parse_ctx.advance_to(f.parse(parse_ctx));
+ using qualified_type =
+ conditional_t(), const T, T>;
+ // format must be const for compatibility with std::format and compilation.
+ const auto& cf = f;
+ ctx.advance_to(cf.format(*static_cast(arg), ctx));
+ }
+};
+
+// To minimize the number of types we need to deal with, long is translated
+// either to int or to long long depending on its size.
+enum { long_short = sizeof(long) == sizeof(int) };
+using long_type = conditional_t;
+using ulong_type = conditional_t;
+
+template struct format_as_result {
+ template ::value || std::is_class::value)>
+ static auto map(U*) -> remove_cvref_t()))>;
+ static auto map(...) -> void;
+
+ using type = decltype(map(static_cast(nullptr)));
+};
+template using format_as_t = typename format_as_result::type;
+
+template
+struct has_format_as
+ : bool_constant, void>::value> {};
+
+#define FMT_MAP_API FMT_CONSTEXPR FMT_ALWAYS_INLINE
+
+// Maps formatting arguments to core types.
+// arg_mapper reports errors by returning unformattable instead of using
+// static_assert because it's used in the is_formattable trait.
+template struct arg_mapper {
+ using char_type = typename Context::char_type;
+
+ FMT_MAP_API auto map(signed char val) -> int { return val; }
+ FMT_MAP_API auto map(unsigned char val) -> unsigned { return val; }
+ FMT_MAP_API auto map(short val) -> int { return val; }
+ FMT_MAP_API auto map(unsigned short val) -> unsigned { return val; }
+ FMT_MAP_API auto map(int val) -> int { return val; }
+ FMT_MAP_API auto map(unsigned val) -> unsigned { return val; }
+ FMT_MAP_API auto map(long val) -> long_type { return val; }
+ FMT_MAP_API auto map(unsigned long val) -> ulong_type { return val; }
+ FMT_MAP_API auto map(long long val) -> long long { return val; }
+ FMT_MAP_API auto map(unsigned long long val) -> unsigned long long {
+ return val;
+ }
+ FMT_MAP_API auto map(int128_opt val) -> int128_opt { return val; }
+ FMT_MAP_API auto map(uint128_opt val) -> uint128_opt { return val; }
+ FMT_MAP_API auto map(bool val) -> bool { return val; }
+
+ template ::value ||
+ std::is_same::value)>
+ FMT_MAP_API auto map(T val) -> char_type {
+ return val;
+ }
+ template ::value ||
+#ifdef __cpp_char8_t
+ std::is_same::value ||
+#endif
+ std::is_same::value ||
+ std::is_same::value) &&
+ !std::is_same::value,
+ int> = 0>
+ FMT_MAP_API auto map(T) -> unformattable_char {
+ return {};
+ }
+
+ FMT_MAP_API auto map(float val) -> float { return val; }
+ FMT_MAP_API auto map(double val) -> double { return val; }
+ FMT_MAP_API auto map(long double val) -> long double { return val; }
+
+ FMT_MAP_API auto map(char_type* val) -> const char_type* { return val; }
+ FMT_MAP_API auto map(const char_type* val) -> const char_type* { return val; }
+ template ,
+ FMT_ENABLE_IF(std::is_same::value &&
+ !std::is_pointer::value)>
+ FMT_MAP_API auto map(const T& val) -> basic_string_view {
+ return to_string_view(val);
+ }
+ template ,
+ FMT_ENABLE_IF(!std::is_same::value &&
+ !std::is_pointer::value)>
+ FMT_MAP_API auto map(const T&) -> unformattable_char {
+ return {};
+ }
+
+ FMT_MAP_API auto map(void* val) -> const void* { return val; }
+ FMT_MAP_API auto map(const void* val) -> const void* { return val; }
+ FMT_MAP_API auto map(std::nullptr_t val) -> const void* { return val; }
+
+ // Use SFINAE instead of a const T* parameter to avoid a conflict with the
+ // array overload.
+ template <
+ typename T,
+ FMT_ENABLE_IF(
+ std::is_pointer::value || std::is_member_pointer::value ||
+ std::is_function::type>::value ||
+ (std::is_array