Skip to content

Commit

Permalink
Cleanup format string API
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Sep 4, 2024
1 parent 1e0c6cd commit e2b7238
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
3 changes: 0 additions & 3 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2806,9 +2806,6 @@ template <typename Char, typename... T> class fstring {
auto get() const -> basic_string_view<Char> { return str_; }
};

template <typename Char, typename... T>
using basic_format_string = typename fstring<Char, T...>::t;

template <typename... T> using format_string = typename fstring<char, T...>::t;

template <typename T, typename Char = char>
Expand Down
16 changes: 7 additions & 9 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ void print(std::ostream& os, format_string<T...> fmt, T&&... args) {
}

FMT_EXPORT
template <typename... Args>
void print(std::wostream& os,
basic_format_string<wchar_t, type_identity_t<Args>...> fmt,
Args&&... args) {
template <typename... T>
void print(std::wostream& os, typename fstring<wchar_t, T...>::t fmt,
T&&... args) {
vprint(os, fmt, fmt::make_format_args<buffered_context<wchar_t>>(args...));
}

Expand All @@ -199,11 +198,10 @@ void println(std::ostream& os, format_string<T...> fmt, T&&... args) {
}

FMT_EXPORT
template <typename... Args>
void println(std::wostream& os,
basic_format_string<wchar_t, type_identity_t<Args>...> fmt,
Args&&... args) {
print(os, L"{}\n", fmt::format(fmt, std::forward<Args>(args)...));
template <typename... T>
void println(std::wostream& os, typename fstring<wchar_t, T...>::t fmt,
T&&... args) {
print(os, L"{}\n", fmt::format(fmt, std::forward<T>(args)...));
}

FMT_END_NAMESPACE
Expand Down
13 changes: 5 additions & 8 deletions include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,14 @@ using wformat_context = buffered_context<wchar_t>;
using wformat_args = basic_format_args<wformat_context>;
using wmemory_buffer = basic_memory_buffer<wchar_t>;

#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
// Workaround broken conversion on older gcc.
template <typename... Args> using wformat_string = wstring_view;
inline auto runtime(wstring_view s) -> wstring_view { return s; }
#else
template <typename... Args>
using wformat_string = basic_format_string<wchar_t, type_identity_t<Args>...>;
template <typename Char, typename... T>
using basic_format_string = fstring<Char, T...>;

template <typename... T>
using wformat_string = typename fstring<wchar_t, T...>::t;
inline auto runtime(wstring_view s) -> runtime_format_string<wchar_t> {
return {{s}};
}
#endif

template <> struct is_char<wchar_t> : std::true_type {};
template <> struct is_char<char16_t> : std::true_type {};
Expand Down

0 comments on commit e2b7238

Please sign in to comment.