From 8bc95b8ed14a4d8a8c9a347127b36937004a9cc1 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Sun, 28 Mar 2021 14:24:48 +0200 Subject: [PATCH] Tag official API for module export * functions * classes * UDLs * other declarations Export everything in namespace 'fmt' from core.h and format.h --- include/fmt/chrono.h | 7 +++++++ include/fmt/color.h | 15 +++++++++++++++ include/fmt/compile.h | 3 +++ include/fmt/core.h | 16 ++++++++++++++++ include/fmt/format.h | 15 ++++++++++++++- include/fmt/locale.h | 3 +++ include/fmt/ostream.h | 6 ++++++ include/fmt/printf.h | 6 ++++++ include/fmt/ranges.h | 3 +++ 9 files changed, 73 insertions(+), 1 deletion(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index eedfa012f1e00..95c76fc989939 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -289,6 +289,8 @@ inline null<> gmtime_r(...) { return null<>(); } inline null<> gmtime_s(...) { return null<>(); } } // namespace detail +FMT_MODULE_EXPORT_BEGIN + /** Converts given time since epoch as ``std::time_t`` value into calendar time, expressed in local time. Unlike ``std::localtime``, this function is @@ -380,6 +382,8 @@ inline std::tm gmtime( return gmtime(std::chrono::system_clock::to_time_t(time_point)); } +FMT_MODULE_EXPORT_END + namespace detail { inline size_t strftime(char* str, size_t count, const char* format, const std::tm* time) { @@ -401,6 +405,8 @@ inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format, } } // namespace detail +FMT_MODULE_EXPORT_BEGIN + template struct formatter, Char> : formatter { @@ -1185,6 +1191,7 @@ struct formatter, Char> { } }; +FMT_MODULE_EXPORT_END FMT_END_NAMESPACE #endif // FMT_CHRONO_H_ diff --git a/include/fmt/color.h b/include/fmt/color.h index 24ccedac73303..0a99ea88dfb0e 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -19,6 +19,8 @@ FMT_BEGIN_NAMESPACE +FMT_MODULE_EXPORT_BEGIN + enum class color : uint32_t { alice_blue = 0xF0F8FF, // rgb(240,248,255) antique_white = 0xFAEBD7, // rgb(250,235,215) @@ -205,6 +207,8 @@ struct rgb { uint8_t b; }; +FMT_MODULE_EXPORT_END + namespace detail { // color is a struct of either a rgb color or a terminal color. @@ -231,6 +235,7 @@ struct color_type { } // namespace detail /** A text style consisting of foreground and background colors and emphasis. */ +FMT_MODULE_EXPORT class text_style { public: FMT_CONSTEXPR text_style(emphasis em = emphasis()) FMT_NOEXCEPT @@ -352,6 +357,8 @@ class text_style { emphasis ems; }; +FMT_MODULE_EXPORT_BEGIN + /** Creates a text style from the foreground (text) color. */ FMT_CONSTEXPR inline text_style fg(detail::color_type foreground) FMT_NOEXCEPT { return text_style(true, foreground); @@ -367,6 +374,8 @@ FMT_CONSTEXPR inline text_style operator|(emphasis lhs, return text_style(lhs) | rhs; } +FMT_MODULE_EXPORT_END + namespace detail { template struct ansi_color_escape { @@ -531,6 +540,7 @@ void vprint(std::FILE* f, const text_style& ts, const S& format, "Elapsed time: {0:.2f} seconds", 1.23); \endrst */ +FMT_MODULE_EXPORT template ::value)> void print(std::FILE* f, const text_style& ts, const S& format_str, @@ -550,12 +560,14 @@ void print(std::FILE* f, const text_style& ts, const S& format_str, "Elapsed time: {0:.2f} seconds", 1.23); \endrst */ +FMT_MODULE_EXPORT template ::value)> void print(const text_style& ts, const S& format_str, const Args&... args) { return print(stdout, ts, format_str, args...); } +FMT_MODULE_EXPORT template > inline std::basic_string vformat( const text_style& ts, const S& format_str, @@ -577,6 +589,7 @@ inline std::basic_string vformat( "The answer is {}", 42); \endrst */ +FMT_MODULE_EXPORT template > inline std::basic_string format(const text_style& ts, const S& format_str, const Args&... args) { @@ -587,6 +600,7 @@ inline std::basic_string format(const text_style& ts, const S& format_str, /** Formats a string with the given text_style and writes the output to ``out``. */ +FMT_MODULE_EXPORT template ::value)> OutputIt vformat_to( @@ -609,6 +623,7 @@ OutputIt vformat_to( fmt::emphasis::bold | fg(fmt::color::red), "{}", 42); \endrst */ +FMT_MODULE_EXPORT template >::value&& detail::is_string::value> diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 580cacdebe25f..111fffc95420a 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -816,6 +816,8 @@ FMT_DEPRECATED auto compile(const Args&... args) return detail::compile(args...); } +FMT_MODULE_EXPORT_BEGIN + #if FMT_USE_CONSTEXPR # ifdef __cpp_if_constexpr @@ -953,6 +955,7 @@ operator""_cf() { } // namespace literals #endif +FMT_MODULE_EXPORT_END FMT_END_NAMESPACE #endif // FMT_COMPILE_H_ diff --git a/include/fmt/core.h b/include/fmt/core.h index 4145bd9e9ed01..f29d381febcdc 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -370,6 +370,8 @@ namespace internal = detail; // DEPRECATED compiled with a different ``-std`` option than the client code (which is not recommended). */ +FMT_MODULE_EXPORT_BEGIN + template class basic_string_view { private: const Char* data_; @@ -523,6 +525,7 @@ constexpr basic_string_view to_string_view(const S& s) { return s; } +FMT_MODULE_EXPORT_END namespace detail { void to_string_view(...); using fmt::v7::to_string_view; @@ -560,6 +563,7 @@ struct error_handler { FMT_NORETURN FMT_API void on_error(const char* message); }; } // namespace detail +FMT_MODULE_EXPORT_BEGIN /** String's character type. */ template using char_t = typename detail::char_t_impl::type; @@ -668,6 +672,7 @@ template struct is_contiguous : std::false_type {}; template struct is_contiguous> : std::true_type {}; +FMT_MODULE_EXPORT_END namespace detail { // Extracts a reference to the container from back_insert_iterator. @@ -1285,6 +1290,7 @@ enum { max_packed_args = 62 / packed_arg_bits }; enum : unsigned long long { is_unpacked_bit = 1ULL << 63 }; enum : unsigned long long { has_named_args_bit = 1ULL << 62 }; } // namespace detail +FMT_MODULE_EXPORT_BEGIN // A formatting argument. It is a trivially copyable/constructible type to // allow storage in basic_memory_buffer. @@ -1394,6 +1400,7 @@ FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg( return vis(monostate()); } +FMT_MODULE_EXPORT_END namespace detail { #if FMT_GCC_VERSION && FMT_GCC_VERSION < 500 @@ -1480,6 +1487,7 @@ inline basic_format_arg make_arg(const T& value) { return make_arg(value); } } // namespace detail +FMT_MODULE_EXPORT_BEGIN // Formatting context. template class basic_format_context { @@ -1536,10 +1544,14 @@ using buffer_context = using format_context = buffer_context; using wformat_context = buffer_context; +FMT_MODULE_EXPORT_END + // Workaround an alias issue: https://stackoverflow.com/q/62767544/471164. #define FMT_BUFFER_CONTEXT(Char) \ basic_format_context, Char> +FMT_MODULE_EXPORT_BEGIN + template using is_formattable = bool_constant>().map(std::declval())), @@ -1782,6 +1794,7 @@ struct wformat_args : basic_format_args { }; #endif +FMT_MODULE_EXPORT_END namespace detail { template ::value)> @@ -1806,6 +1819,7 @@ FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); inline void vprint_mojibake(std::FILE*, string_view, format_args) {} #endif } // namespace detail +FMT_MODULE_EXPORT_BEGIN /** Formats a string and writes the output to ``out``. */ // GCC 8 and earlier cannot handle std::back_insert_iterator with @@ -1954,6 +1968,8 @@ inline void print(const S& format_str, Args&&... args) { : detail::vprint_mojibake(stdout, to_string_view(format_str), vargs); } + +FMT_MODULE_EXPORT_END FMT_GCC_PRAGMA("GCC pop_options") FMT_END_NAMESPACE diff --git a/include/fmt/format.h b/include/fmt/format.h index 32b42dd54c54f..b4ef5a07419d2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -692,6 +692,8 @@ void iterator_buffer::flush() { } } // namespace detail +FMT_MODULE_EXPORT_BEGIN + // The number of characters to store in the basic_memory_buffer object itself // to avoid dynamic memory allocation. enum { inline_buffer_size = 500 }; @@ -859,6 +861,7 @@ class FMT_API format_error : public std::runtime_error { ~format_error() FMT_NOEXCEPT FMT_OVERRIDE; }; +FMT_MODULE_EXPORT_END namespace detail { template @@ -1255,7 +1258,7 @@ template struct fill_t { } }; } // namespace detail - +FMT_MODULE_EXPORT_BEGIN // We cannot use enum classes as bit fields because of a gcc bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414. namespace align { @@ -1291,6 +1294,7 @@ template struct basic_format_specs { using format_specs = basic_format_specs; +FMT_MODULE_EXPORT_END namespace detail { namespace dragonbox { @@ -3305,6 +3309,7 @@ FMT_API void format_error_code(buffer& out, int error_code, FMT_API void report_error(format_func func, int error_code, string_view message) FMT_NOEXCEPT; } // namespace detail +FMT_MODULE_EXPORT_BEGIN template using arg_formatter FMT_DEPRECATED_ALIAS = @@ -3833,6 +3838,8 @@ std::basic_string to_string(const basic_memory_buffer& buf) { return std::basic_string(buf.data(), size); } +FMT_MODULE_EXPORT_END + template void detail::vformat_to( detail::buffer& buf, basic_string_view format_str, @@ -3881,6 +3888,8 @@ extern template int snprintf_float(long double value, } // namespace detail #endif +FMT_MODULE_EXPORT_BEGIN + template , FMT_ENABLE_IF(detail::is_string::value)> inline void vformat_to( @@ -3965,6 +3974,7 @@ void vprint(basic_string_view format_str, wformat_args args) { vprint(stdout, format_str, args); } +FMT_MODULE_EXPORT_END #if FMT_USE_USER_DEFINED_LITERALS namespace detail { template struct udl_formatter { @@ -3984,6 +3994,7 @@ template struct udl_arg { } }; } // namespace detail +FMT_MODULE_EXPORT_BEGIN inline namespace literals { /** @@ -4022,6 +4033,8 @@ constexpr detail::udl_arg operator"" _a(const wchar_t* s, size_t) { return {s}; } } // namespace literals + +FMT_MODULE_EXPORT_END #endif // FMT_USE_USER_DEFINED_LITERALS FMT_END_NAMESPACE diff --git a/include/fmt/locale.h b/include/fmt/locale.h index b5990ef19efba..e79140a1a19a1 100644 --- a/include/fmt/locale.h +++ b/include/fmt/locale.h @@ -25,6 +25,8 @@ std::basic_string vformat( } } // namespace detail +FMT_MODULE_EXPORT_BEGIN + template > inline std::basic_string vformat( const std::locale& loc, const S& format_str, @@ -59,6 +61,7 @@ inline auto format_to(OutputIt out, const std::locale& loc, const S& format_str, return vformat_to(out, loc, to_string_view(format_str), vargs); } +FMT_MODULE_EXPORT_END FMT_END_NAMESPACE #endif // FMT_LOCALE_H_ diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 411588c626a59..0a3230fc3bbed 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -14,9 +14,13 @@ FMT_BEGIN_NAMESPACE +FMT_MODULE_EXPORT_BEGIN + template class basic_printf_parse_context; template class basic_printf_context; +FMT_MODULE_EXPORT_END + namespace detail { template class formatbuf : public std::basic_streambuf { @@ -151,6 +155,7 @@ struct fallback_formatter::value>> }; } // namespace detail +FMT_MODULE_EXPORT template void vprint(std::basic_ostream& os, basic_string_view format_str, basic_format_args>> args) { @@ -168,6 +173,7 @@ void vprint(std::basic_ostream& os, basic_string_view format_str, fmt::print(cerr, "Don't {}!", "panic"); \endrst */ +FMT_MODULE_EXPORT template ::value, char_t>> void print(std::basic_ostream& os, const S& format_str, Args&&... args) { diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 691fc0ff405c4..0fefbca742313 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -194,10 +194,12 @@ FMT_DEPRECATED void printf(detail::buffer& buf, } using detail::vprintf; +// already exported through "ostream.h" above template class basic_printf_parse_context : public basic_format_parse_context { using basic_format_parse_context::basic_format_parse_context; }; +// already exported through "ostream.h" above template class basic_printf_context; /** @@ -567,6 +569,8 @@ OutputIt basic_printf_context::format() { out, basic_string_view(start, detail::to_unsigned(it - start))); } +FMT_MODULE_EXPORT_BEGIN + template using basic_printf_context_t = basic_printf_context, Char>; @@ -717,6 +721,8 @@ inline int fprintf(std::basic_ostream& os, const S& format_str, return vfprintf(os, to_string_view(format_str), make_format_args(args...)); } + +FMT_MODULE_EXPORT_END FMT_END_NAMESPACE #endif // FMT_PRINTF_H_ diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 0ebf965264428..4b0de394df2c5 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -416,6 +416,8 @@ struct formatter, Char> { } }; +FMT_MODULE_EXPORT_BEGIN + /** \rst Returns an object that formats `tuple` with elements separated by `sep`. @@ -462,6 +464,7 @@ arg_join join(std::initializer_list list, return join(std::begin(list), std::end(list), sep); } +FMT_MODULE_EXPORT_END FMT_END_NAMESPACE #endif // FMT_RANGES_H_