This commit is contained in:
Victor Zverovich 2024-09-06 13:20:44 -07:00
parent f5a16a484b
commit 158893b384
6 changed files with 24 additions and 48 deletions

View File

@ -17,7 +17,6 @@
#include "format.h" // std_string_view
FMT_BEGIN_NAMESPACE
namespace detail {
template <typename T> struct is_reference_wrapper : std::false_type {};
@ -72,8 +71,7 @@ class dynamic_arg_list {
* It can be implicitly converted into `fmt::basic_format_args` for passing
* into type-erased formatting functions such as `fmt::vformat`.
*/
template <typename Context>
class dynamic_format_arg_store {
template <typename Context> class dynamic_format_arg_store {
private:
using char_type = typename Context::char_type;
@ -201,7 +199,7 @@ class dynamic_format_arg_store {
void clear() {
data_.clear();
named_info_.clear();
dynamic_args_ = detail::dynamic_arg_list();
dynamic_args_ = {};
}
/// Reserves space to store at least `new_cap` arguments including

View File

@ -441,9 +441,9 @@ template <typename T> struct styled_arg : detail::view {
};
template <typename Char>
void vformat_to(
buffer<Char>& buf, const text_style& ts, basic_string_view<Char> format_str,
basic_format_args<buffered_context<type_identity_t<Char>>> args) {
void vformat_to(buffer<Char>& buf, const text_style& ts,
basic_string_view<Char> fmt,
basic_format_args<buffered_context<Char>> args) {
bool has_style = false;
if (ts.has_emphasis()) {
has_style = true;
@ -460,10 +460,9 @@ void vformat_to(
auto background = detail::make_background_color<Char>(ts.get_background());
buf.append(background.begin(), background.end());
}
detail::vformat_to(buf, format_str, args, {});
detail::vformat_to(buf, fmt, args);
if (has_style) detail::reset_color<Char>(buf);
}
} // namespace detail
inline void vprint(FILE* f, const text_style& ts, string_view fmt,

View File

@ -143,7 +143,7 @@ FMT_END_NAMESPACE
#ifndef FMT_USE_USER_LITERALS
// EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs.
# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION || \
FMT_MSC_VERSION >= 1900) && \
FMT_MSC_VERSION >= 1900) && \
(!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480)
# define FMT_USE_USER_LITERALS 1
# else
@ -3807,8 +3807,8 @@ template <typename Char> struct udl_arg {
return {str, std::forward<T>(value)};
}
};
# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS
#endif // FMT_USE_USER_LITERALS
# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS
#endif // FMT_USE_USER_LITERALS
template <typename Char> struct format_handler {
parse_context<Char> parse_ctx;
@ -3857,7 +3857,6 @@ template <typename Char> struct format_handler {
};
// DEPRECATED!
// Use vformat_args and avoid type_identity to keep symbols short.
template <typename Char = char> struct vformat_args {
using type = basic_format_args<buffered_context<Char>>;
};
@ -4349,8 +4348,7 @@ template <typename OutputIt, typename Locale,
detail::is_locale<Locale>::value)>
auto vformat_to(OutputIt out, const Locale& loc, string_view fmt,
format_args args) -> OutputIt {
using detail::get_buffer;
auto&& buf = get_buffer<char>(out);
auto&& buf = detail::get_buffer<char>(out);
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
return detail::get_iterator(buf, out);
}
@ -4374,7 +4372,6 @@ FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc,
}
FMT_END_EXPORT
FMT_END_NAMESPACE
#ifdef FMT_HEADER_ONLY

View File

@ -147,8 +147,8 @@ FMT_API std::system_error vwindows_error(int error_code, string_view format_str,
* }
*/
template <typename... T>
auto windows_error(int error_code, string_view message,
const T&... args) -> std::system_error {
auto windows_error(int error_code, string_view message, const T&... args)
-> std::system_error {
return vwindows_error(error_code, message, vargs<T...>{{args...}});
}

View File

@ -148,25 +148,14 @@ constexpr auto streamed(const T& value) -> detail::streamed_view<T> {
return {value};
}
namespace detail {
inline void vprint_directly(std::ostream& os, string_view format_str,
format_args args) {
auto buffer = memory_buffer();
detail::vformat_to(buffer, format_str, args);
detail::write_buffer(os, buffer);
}
} // namespace detail
FMT_EXPORT template <typename Char>
void vprint(std::basic_ostream<Char>& os,
basic_string_view<type_identity_t<Char>> fmt,
typename detail::vformat_args<Char>::type args) {
auto buffer = basic_memory_buffer<Char>();
detail::vformat_to(buffer, fmt, args);
if (detail::write_ostream_unicode(os, {buffer.data(), buffer.size()})) return;
detail::write_buffer(os, buffer);
if (!detail::write_ostream_unicode(os, {buffer.data(), buffer.size()}))
detail::write_buffer(os, buffer);
}
/**
@ -180,7 +169,9 @@ FMT_EXPORT template <typename... T>
void print(std::ostream& os, format_string<T...> fmt, T&&... args) {
fmt::vargs<T...> vargs = {{args...}};
if (FMT_USE_UTF8) return vprint(os, fmt, vargs);
detail::vprint_directly(os, fmt, vargs);
auto buffer = memory_buffer();
detail::vformat_to(buffer, fmt, vargs);
detail::write_buffer(os, buffer);
}
FMT_EXPORT

View File

@ -44,18 +44,6 @@ template <typename T> class is_set {
!std::is_void<decltype(check<T>(nullptr))>::value && !is_map<T>::value;
};
template <typename... Ts> struct conditional_helper {};
template <typename T, typename _ = void> struct is_range_ : std::false_type {};
#if !FMT_MSC_VERSION || FMT_MSC_VERSION > 1800
# define FMT_DECLTYPE_RETURN(val) \
->decltype(val) { return val; } \
static_assert( \
true, "") // This makes it so that a semicolon is required after the
// macro, which helps clang-format handle the formatting.
// C array overload
template <typename T, std::size_t N>
auto range_begin(const T (&arr)[N]) -> const T* {
@ -76,9 +64,13 @@ struct has_member_fn_begin_end_t<T, void_t<decltype(*std::declval<T>().begin()),
// Member function overloads.
template <typename T>
auto range_begin(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).begin());
auto range_begin(T&& rng) -> decltype(static_cast<T&&>(rng).begin()) {
return static_cast<T&&>(rng).begin();
}
template <typename T>
auto range_end(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).end());
auto range_end(T&& rng) -> decltype(static_cast<T&&>(rng).end()) {
return static_cast<T&&>(rng).end();
}
// ADL overloads. Only participate in overload resolution if member functions
// are not found.
@ -115,12 +107,11 @@ struct has_mutable_begin_end<
// SFINAE properly unless there are distinct types
int>> : std::true_type {};
template <typename T, typename _ = void> struct is_range_ : std::false_type {};
template <typename T>
struct is_range_<T, void>
: std::integral_constant<bool, (has_const_begin_end<T>::value ||
has_mutable_begin_end<T>::value)> {};
# undef FMT_DECLTYPE_RETURN
#endif
// tuple_size and tuple_element check.
template <typename T> class is_tuple_like_ {