From f84e720cde699d7c83faee9ec7c74874b8b48366 Mon Sep 17 00:00:00 2001 From: Matthias Moulin Date: Tue, 9 Apr 2024 20:41:21 +0200 Subject: [PATCH] Added FMT_IMPORT_STD feature macro --- include/fmt/args.h | 8 +++-- include/fmt/base.h | 6 ++-- include/fmt/chrono.h | 20 ++++++----- include/fmt/compile.h | 4 ++- include/fmt/format-inl.h | 14 ++++---- include/fmt/format.h | 28 ++++++++------- include/fmt/os.h | 10 +++--- include/fmt/ostream.h | 4 ++- include/fmt/printf.h | 6 ++-- include/fmt/ranges.h | 10 +++--- include/fmt/std.h | 36 ++++++++++--------- include/fmt/xchar.h | 6 ++-- src/fmt.cc | 76 +++++++++++++++++++++++----------------- src/os.cc | 4 ++- 14 files changed, 137 insertions(+), 95 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index b77a2d0661122..71c3bb908830f 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -8,9 +8,11 @@ #ifndef FMT_ARGS_H_ #define FMT_ARGS_H_ -#include // std::reference_wrapper -#include // std::unique_ptr -#include +#ifndef FMT_IMPORT_STD +# include // std::reference_wrapper +# include // std::unique_ptr +# include +#endif #include "format.h" // std_string_view diff --git a/include/fmt/base.h b/include/fmt/base.h index f46d7e470e6d0..64fb15b9981c4 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -12,9 +12,11 @@ #include // FILE #include // strlen +#ifndef FMT_IMPORT_STD // is also included transitively from . -#include // std::byte -#include // std::enable_if +# include // std::byte +# include // std::enable_if +#endif // The fmt library version in the form major * 10000 + minor * 100 + patch. #define FMT_VERSION 100202 diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index d2e10b56b9332..6360d903e9e6a 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -8,15 +8,17 @@ #ifndef FMT_CHRONO_H_ #define FMT_CHRONO_H_ -#include -#include -#include // std::isfinite -#include // std::memcpy -#include -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include // std::isfinite +# include // std::memcpy +# include +# include +# include +# include +# include +#endif #include "format.h" diff --git a/include/fmt/compile.h b/include/fmt/compile.h index d6278521fd0c8..65c68a4b755b2 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -8,7 +8,9 @@ #ifndef FMT_COMPILE_H_ #define FMT_COMPILE_H_ -#include // std::back_inserter +#ifndef FMT_IMPORT_STD +# include // std::back_inserter +#endif #include "format.h" diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 5a9afd1ff35a4..5bf56f2cbf553 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -8,13 +8,15 @@ #ifndef FMT_FORMAT_INL_H_ #define FMT_FORMAT_INL_H_ -#include -#include // errno -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include // errno +# include +# include +# include +#endif -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) # include #endif diff --git a/include/fmt/format.h b/include/fmt/format.h index 8ab8f263cf721..f15b8dbb5e23d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -38,30 +38,34 @@ # define FMT_REMOVE_TRANSITIVE_INCLUDES #endif -#include // std::signbit -#include // uint32_t -#include // std::memcpy -#include // std::initializer_list -#include // std::numeric_limits -#if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) +#ifndef FMT_IMPORT_STD +# include // std::signbit +# include // uint32_t +# include // std::memcpy +# include // std::initializer_list +# include // std::numeric_limits +# if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) // Workaround for pre gcc 5 libstdc++. -# include // std::allocator_traits +# include // std::allocator_traits +# endif +# include // std::runtime_error +# include // std::string +# include // std::system_error #endif -#include // std::runtime_error -#include // std::string -#include // std::system_error #include "base.h" // Checking FMT_CPLUSPLUS for warning suppression in MSVC. -#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L +#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L && !defined(FMT_IMPORT_STD) # include // std::bit_cast #endif // libc++ supports string_view in pre-c++17. #if FMT_HAS_INCLUDE() && \ (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION)) -# include +# ifndef FMT_IMPORT_STD +# include +# endif # define FMT_USE_STRING_VIEW #endif diff --git a/include/fmt/os.h b/include/fmt/os.h index 3a10c9303f11e..c98256920cdcb 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -8,10 +8,12 @@ #ifndef FMT_OS_H_ #define FMT_OS_H_ -#include -#include -#include -#include // std::system_error +#ifndef FMT_IMPORT_STD +# include +# include +# include +# include // std::system_error +#endif #include "format.h" diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index f9ba9d7b25b64..7ab245802611d 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -8,7 +8,9 @@ #ifndef FMT_OSTREAM_H_ #define FMT_OSTREAM_H_ -#include // std::filebuf +#ifndef FMT_IMPORT_STD +# include // std::filebuf +#endif #ifdef _WIN32 # ifdef __GLIBCXX__ diff --git a/include/fmt/printf.h b/include/fmt/printf.h index c060952d9e8be..fb57d23585f97 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -8,8 +8,10 @@ #ifndef FMT_PRINTF_H_ #define FMT_PRINTF_H_ -#include // std::max -#include // std::numeric_limits +#ifndef FMT_IMPORT_STD +# include // std::max +# include // std::numeric_limits +#endif #include "format.h" diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index f2b0f0e944dce..86f9e01e5ffad 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -8,10 +8,12 @@ #ifndef FMT_RANGES_H_ #define FMT_RANGES_H_ -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include +# include +#endif #include "format.h" diff --git a/include/fmt/std.h b/include/fmt/std.h index 7085cae8170af..f437a847e636d 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -8,17 +8,19 @@ #ifndef FMT_STD_H_ #define FMT_STD_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif #include "format.h" #include "ostream.h" @@ -28,22 +30,24 @@ #endif // Checking FMT_CPLUSPLUS for warning suppression in MSVC. #if FMT_CPLUSPLUS >= 201703L -# if FMT_HAS_INCLUDE() +# if FMT_HAS_INCLUDE() && !defined(FMT_IMPORT_STD) # include # endif -# if FMT_HAS_INCLUDE() +# if FMT_HAS_INCLUDE() && !defined(FMT_IMPORT_STD) # include # endif -# if FMT_HAS_INCLUDE() +# if FMT_HAS_INCLUDE() && !defined(FMT_IMPORT_STD) # include # endif #endif -#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 202002L +#if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 202002L && \ + !defined(FMT_IMPORT_STD) # include #endif -#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() +#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() && \ + !defined(FMT_IMPORT_STD) # include #endif diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 61a4b54fca5d7..557dbe1d3adbc 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -8,13 +8,15 @@ #ifndef FMT_XCHAR_H_ #define FMT_XCHAR_H_ -#include +#ifndef FMT_IMPORT_STD +# include +#endif #include "color.h" #include "format.h" #include "ranges.h" -#ifndef FMT_STATIC_THOUSANDS_SEPARATOR +#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD) # include #endif diff --git a/src/fmt.cc b/src/fmt.cc index 6cff309d41c62..798c026976470 100644 --- a/src/fmt.cc +++ b/src/fmt.cc @@ -2,38 +2,46 @@ module; // Put all implementation-provided headers into the global module fragment // to prevent attachment to this module. -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifndef FMT_IMPORT_STD +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#else +# include +# include +# include +# include +# include +#endif #if __has_include() # include @@ -70,6 +78,10 @@ module; export module fmt; +#ifdef FMT_IMPORT_STD +import std; +#endif + #define FMT_EXPORT export #define FMT_BEGIN_EXPORT export { #define FMT_END_EXPORT } diff --git a/src/os.cc b/src/os.cc index 70a4a04c4d3d3..0898c2853714f 100644 --- a/src/os.cc +++ b/src/os.cc @@ -12,7 +12,9 @@ #include "fmt/os.h" -#include +#ifndef FMT_IMPORT_STD +# include +#endif #if FMT_USE_FCNTL # include