mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-10 14:30:09 +00:00
Do *not* export namespace detail
Introduce `FMT_BEGIN_DETAIL_NAMESPACE` and `FMT_END_DETAIL_NAMESPACE` for `namespace detail` sections embedded in that part of the code that contains all declarations that are exported from the module, i.e. which is enclosed by `FMT_MODULE_EXPORT_BEGIN` and `FMT_MODULE_EXPORT_END`. Given a correct implementation of C++20 modules, neither the name `fmt::detail` nor any of its contents will become visible outside of the module.
This commit is contained in:
parent
588bdb5404
commit
5466373a11
@ -382,9 +382,8 @@ inline std::tm gmtime(
|
|||||||
return gmtime(std::chrono::system_clock::to_time_t(time_point));
|
return gmtime(std::chrono::system_clock::to_time_t(time_point));
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
inline size_t strftime(char* str, size_t count, const char* format,
|
inline size_t strftime(char* str, size_t count, const char* format,
|
||||||
const std::tm* time) {
|
const std::tm* time) {
|
||||||
// Assign to a pointer to suppress GCCs -Wformat-nonliteral
|
// Assign to a pointer to suppress GCCs -Wformat-nonliteral
|
||||||
@ -403,9 +402,8 @@ inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format,
|
|||||||
wcsftime = std::wcsftime;
|
wcsftime = std::wcsftime;
|
||||||
return wcsftime(str, count, format, time);
|
return wcsftime(str, count, format, time);
|
||||||
}
|
}
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
template <typename Char, typename Duration>
|
template <typename Char, typename Duration>
|
||||||
struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
|
||||||
@ -458,7 +456,8 @@ template <typename Char> struct formatter<std::tm, Char> {
|
|||||||
basic_string_view<Char> specs;
|
basic_string_view<Char> specs;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
|
|
||||||
template <typename Period> FMT_CONSTEXPR const char* get_units() {
|
template <typename Period> FMT_CONSTEXPR const char* get_units() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -1078,7 +1077,8 @@ struct chrono_formatter {
|
|||||||
out = format_duration_unit<char_type, Period>(out);
|
out = format_duration_unit<char_type, Period>(out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace detail
|
|
||||||
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
template <typename Rep, typename Period, typename Char>
|
template <typename Rep, typename Period, typename Char>
|
||||||
struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
struct formatter<std::chrono::duration<Rep, Period>, Char> {
|
||||||
|
@ -206,8 +206,7 @@ struct rgb {
|
|||||||
uint8_t b;
|
uint8_t b;
|
||||||
};
|
};
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
// color is a struct of either a rgb color or a terminal color.
|
// color is a struct of either a rgb color or a terminal color.
|
||||||
struct color_type {
|
struct color_type {
|
||||||
@ -230,8 +229,8 @@ struct color_type {
|
|||||||
uint32_t rgb_color;
|
uint32_t rgb_color;
|
||||||
} value;
|
} value;
|
||||||
};
|
};
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
/** A text style consisting of foreground and background colors and emphasis. */
|
/** A text style consisting of foreground and background colors and emphasis. */
|
||||||
class text_style {
|
class text_style {
|
||||||
@ -370,8 +369,7 @@ FMT_CONSTEXPR inline text_style operator|(emphasis lhs,
|
|||||||
return text_style(lhs) | rhs;
|
return text_style(lhs) | rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <typename Char> struct ansi_color_escape {
|
template <typename Char> struct ansi_color_escape {
|
||||||
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
|
FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color,
|
||||||
@ -512,8 +510,8 @@ void vformat_to(buffer<Char>& buf, const text_style& ts,
|
|||||||
detail::vformat_to(buf, format_str, args);
|
detail::vformat_to(buf, format_str, args);
|
||||||
if (has_style) detail::reset_color<Char>(buf);
|
if (has_style) detail::reset_color<Char>(buf);
|
||||||
}
|
}
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
template <typename S, typename Char = char_t<S>>
|
template <typename S, typename Char = char_t<S>>
|
||||||
void vprint(std::FILE* f, const text_style& ts, const S& format,
|
void vprint(std::FILE* f, const text_style& ts, const S& format,
|
||||||
|
@ -241,6 +241,14 @@
|
|||||||
#ifndef FMT_MODULE_EXPORT_END
|
#ifndef FMT_MODULE_EXPORT_END
|
||||||
# define FMT_MODULE_EXPORT_END
|
# define FMT_MODULE_EXPORT_END
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
|
# define FMT_BEGIN_DETAIL_NAMESPACE \
|
||||||
|
namespace detail {
|
||||||
|
#endif
|
||||||
|
#ifndef FMT_END_DETAIL_NAMESPACE
|
||||||
|
# define FMT_END_DETAIL_NAMESPACE \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
|
#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
|
||||||
# define FMT_CLASS_API FMT_MSC_WARNING(suppress : 4275)
|
# define FMT_CLASS_API FMT_MSC_WARNING(suppress : 4275)
|
||||||
@ -317,8 +325,6 @@ template <typename T> using type_identity_t = typename type_identity<T>::type;
|
|||||||
|
|
||||||
struct monostate {};
|
struct monostate {};
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
|
||||||
|
|
||||||
// An enable_if helper to be used in template parameters which results in much
|
// 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
|
// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
|
||||||
// to workaround a bug in MSVC 2019 (see #1140 and #1186).
|
// to workaround a bug in MSVC 2019 (see #1140 and #1186).
|
||||||
@ -328,7 +334,7 @@ FMT_MODULE_EXPORT_END
|
|||||||
# define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
|
# define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace detail {
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
|
|
||||||
constexpr FMT_INLINE bool is_constant_evaluated() FMT_NOEXCEPT {
|
constexpr FMT_INLINE bool is_constant_evaluated() FMT_NOEXCEPT {
|
||||||
#ifdef __cpp_lib_is_constant_evaluated
|
#ifdef __cpp_lib_is_constant_evaluated
|
||||||
@ -393,7 +399,8 @@ template <typename Char> constexpr bool is_unicode() {
|
|||||||
return FMT_UNICODE || sizeof(Char) != 1 ||
|
return FMT_UNICODE || sizeof(Char) != 1 ||
|
||||||
(sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
|
(sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
|
||||||
}
|
}
|
||||||
} // namespace detail
|
|
||||||
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
|
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
|
||||||
@ -402,8 +409,6 @@ template <typename Char> constexpr bool is_unicode() {
|
|||||||
compiled with a different ``-std`` option than the client code (which is not
|
compiled with a different ``-std`` option than the client code (which is not
|
||||||
recommended).
|
recommended).
|
||||||
*/
|
*/
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
|
||||||
|
|
||||||
template <typename Char> class basic_string_view {
|
template <typename Char> class basic_string_view {
|
||||||
private:
|
private:
|
||||||
const Char* data_;
|
const Char* data_;
|
||||||
@ -552,8 +557,8 @@ constexpr basic_string_view<typename S::char_type> to_string_view(const S& s) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
void to_string_view(...);
|
void to_string_view(...);
|
||||||
using fmt::v7::to_string_view;
|
using fmt::v7::to_string_view;
|
||||||
|
|
||||||
@ -589,8 +594,8 @@ struct error_handler {
|
|||||||
// This function is intentionally not constexpr to give a compile-time error.
|
// This function is intentionally not constexpr to give a compile-time error.
|
||||||
FMT_NORETURN FMT_API void on_error(const char* message);
|
FMT_NORETURN FMT_API void on_error(const char* message);
|
||||||
};
|
};
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
/** String's character type. */
|
/** String's character type. */
|
||||||
template <typename S> using char_t = typename detail::char_t_impl<S>::type;
|
template <typename S> using char_t = typename detail::char_t_impl<S>::type;
|
||||||
@ -700,8 +705,7 @@ template <typename T> struct is_contiguous : std::false_type {};
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
struct is_contiguous<std::basic_string<Char>> : std::true_type {};
|
struct is_contiguous<std::basic_string<Char>> : std::true_type {};
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
// Extracts a reference to the container from back_insert_iterator.
|
// Extracts a reference to the container from back_insert_iterator.
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
@ -1320,8 +1324,8 @@ enum { packed_arg_bits = 4 };
|
|||||||
enum { max_packed_args = 62 / packed_arg_bits };
|
enum { max_packed_args = 62 / packed_arg_bits };
|
||||||
enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
|
enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
|
||||||
enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
|
enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
// A formatting argument. It is a trivially copyable/constructible type to
|
// A formatting argument. It is a trivially copyable/constructible type to
|
||||||
// allow storage in basic_memory_buffer.
|
// allow storage in basic_memory_buffer.
|
||||||
@ -1431,8 +1435,7 @@ FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg(
|
|||||||
return vis(monostate());
|
return vis(monostate());
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
|
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
|
||||||
// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
|
// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
|
||||||
@ -1517,8 +1520,8 @@ template <bool IS_PACKED, typename Context, type, typename T,
|
|||||||
inline basic_format_arg<Context> make_arg(const T& value) {
|
inline basic_format_arg<Context> make_arg(const T& value) {
|
||||||
return make_arg<Context>(value);
|
return make_arg<Context>(value);
|
||||||
}
|
}
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
// Formatting context.
|
// Formatting context.
|
||||||
template <typename OutputIt, typename Char> class basic_format_context {
|
template <typename OutputIt, typename Char> class basic_format_context {
|
||||||
@ -1576,14 +1579,10 @@ using buffer_context =
|
|||||||
using format_context = buffer_context<char>;
|
using format_context = buffer_context<char>;
|
||||||
using wformat_context = buffer_context<wchar_t>;
|
using wformat_context = buffer_context<wchar_t>;
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
|
||||||
|
|
||||||
// Workaround an alias issue: https://stackoverflow.com/q/62767544/471164.
|
// Workaround an alias issue: https://stackoverflow.com/q/62767544/471164.
|
||||||
#define FMT_BUFFER_CONTEXT(Char) \
|
#define FMT_BUFFER_CONTEXT(Char) \
|
||||||
basic_format_context<detail::buffer_appender<Char>, Char>
|
basic_format_context<detail::buffer_appender<Char>, Char>
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
|
||||||
|
|
||||||
template <typename T, typename Char = char>
|
template <typename T, typename Char = char>
|
||||||
using is_formattable = bool_constant<
|
using is_formattable = bool_constant<
|
||||||
!std::is_same<decltype(detail::arg_mapper<buffer_context<Char>>().map(
|
!std::is_same<decltype(detail::arg_mapper<buffer_context<Char>>().map(
|
||||||
@ -1827,7 +1826,8 @@ enum type { none, minus, plus, space };
|
|||||||
}
|
}
|
||||||
using sign_t = sign::type;
|
using sign_t = sign::type;
|
||||||
|
|
||||||
namespace detail {
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
|
|
||||||
void throw_format_error(const char* message);
|
void throw_format_error(const char* message);
|
||||||
|
|
||||||
// Workaround an array initialization issue in gcc 4.8.
|
// Workaround an array initialization issue in gcc 4.8.
|
||||||
@ -1853,7 +1853,8 @@ template <typename Char> struct fill_t {
|
|||||||
return data_[index];
|
return data_[index];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace detail
|
|
||||||
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
// Format specifiers for built-in and string types.
|
// Format specifiers for built-in and string types.
|
||||||
template <typename Char> struct basic_format_specs {
|
template <typename Char> struct basic_format_specs {
|
||||||
@ -1878,8 +1879,7 @@ template <typename Char> struct basic_format_specs {
|
|||||||
|
|
||||||
using format_specs = basic_format_specs<char>;
|
using format_specs = basic_format_specs<char>;
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
enum class arg_id_kind { none, index, name };
|
enum class arg_id_kind { none, index, name };
|
||||||
|
|
||||||
@ -2583,8 +2583,8 @@ FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
|
inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
|
||||||
#endif
|
#endif
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
/** Formats a string and writes the output to ``out``. */
|
/** Formats a string and writes the output to ``out``. */
|
||||||
// GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with
|
// GCC 8 and earlier cannot handle std::back_insert_iterator<Container> with
|
||||||
|
@ -802,8 +802,7 @@ class FMT_API format_error : public std::runtime_error {
|
|||||||
~format_error() FMT_NOEXCEPT FMT_OVERRIDE FMT_MSC_DEFAULT;
|
~format_error() FMT_NOEXCEPT FMT_OVERRIDE FMT_MSC_DEFAULT;
|
||||||
};
|
};
|
||||||
|
|
||||||
FMT_MODULE_EXPORT_END
|
FMT_BEGIN_DETAIL_NAMESPACE
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
inline void throw_format_error(const char* message) {
|
inline void throw_format_error(const char* message) {
|
||||||
FMT_THROW(format_error(message));
|
FMT_THROW(format_error(message));
|
||||||
@ -2534,8 +2533,8 @@ FMT_API void format_error_code(buffer<char>& out, int error_code,
|
|||||||
|
|
||||||
FMT_API void report_error(format_func func, int error_code,
|
FMT_API void report_error(format_func func, int error_code,
|
||||||
const char* message) FMT_NOEXCEPT;
|
const char* message) FMT_NOEXCEPT;
|
||||||
} // namespace detail
|
|
||||||
FMT_MODULE_EXPORT_BEGIN
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
template <typename OutputIt, typename Char>
|
template <typename OutputIt, typename Char>
|
||||||
using arg_formatter FMT_DEPRECATED_ALIAS =
|
using arg_formatter FMT_DEPRECATED_ALIAS =
|
||||||
|
@ -70,6 +70,12 @@ export module fmt;
|
|||||||
#define FMT_MODULE_EXPORT export
|
#define FMT_MODULE_EXPORT export
|
||||||
#define FMT_MODULE_EXPORT_BEGIN export {
|
#define FMT_MODULE_EXPORT_BEGIN export {
|
||||||
#define FMT_MODULE_EXPORT_END }
|
#define FMT_MODULE_EXPORT_END }
|
||||||
|
#define FMT_BEGIN_DETAIL_NAMESPACE \
|
||||||
|
} \
|
||||||
|
namespace detail {
|
||||||
|
#define FMT_END_DETAIL_NAMESPACE \
|
||||||
|
} \
|
||||||
|
export {
|
||||||
|
|
||||||
// all library-provided declarations and definitions
|
// all library-provided declarations and definitions
|
||||||
// must be in the module purview to be exported
|
// must be in the module purview to be exported
|
||||||
|
Loading…
Reference in New Issue
Block a user