mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 03:07:36 +02:00
Cleanup
This commit is contained in:
@ -17,7 +17,6 @@
|
|||||||
#include "format.h" // std_string_view
|
#include "format.h" // std_string_view
|
||||||
|
|
||||||
FMT_BEGIN_NAMESPACE
|
FMT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename T> struct is_reference_wrapper : std::false_type {};
|
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
|
* It can be implicitly converted into `fmt::basic_format_args` for passing
|
||||||
* into type-erased formatting functions such as `fmt::vformat`.
|
* into type-erased formatting functions such as `fmt::vformat`.
|
||||||
*/
|
*/
|
||||||
template <typename Context>
|
template <typename Context> class dynamic_format_arg_store {
|
||||||
class dynamic_format_arg_store {
|
|
||||||
private:
|
private:
|
||||||
using char_type = typename Context::char_type;
|
using char_type = typename Context::char_type;
|
||||||
|
|
||||||
@ -201,7 +199,7 @@ class dynamic_format_arg_store {
|
|||||||
void clear() {
|
void clear() {
|
||||||
data_.clear();
|
data_.clear();
|
||||||
named_info_.clear();
|
named_info_.clear();
|
||||||
dynamic_args_ = detail::dynamic_arg_list();
|
dynamic_args_ = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reserves space to store at least `new_cap` arguments including
|
/// Reserves space to store at least `new_cap` arguments including
|
||||||
|
@ -441,9 +441,9 @@ template <typename T> struct styled_arg : detail::view {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void vformat_to(
|
void vformat_to(buffer<Char>& buf, const text_style& ts,
|
||||||
buffer<Char>& buf, const text_style& ts, basic_string_view<Char> format_str,
|
basic_string_view<Char> fmt,
|
||||||
basic_format_args<buffered_context<type_identity_t<Char>>> args) {
|
basic_format_args<buffered_context<Char>> args) {
|
||||||
bool has_style = false;
|
bool has_style = false;
|
||||||
if (ts.has_emphasis()) {
|
if (ts.has_emphasis()) {
|
||||||
has_style = true;
|
has_style = true;
|
||||||
@ -460,10 +460,9 @@ void vformat_to(
|
|||||||
auto background = detail::make_background_color<Char>(ts.get_background());
|
auto background = detail::make_background_color<Char>(ts.get_background());
|
||||||
buf.append(background.begin(), background.end());
|
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);
|
if (has_style) detail::reset_color<Char>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
inline void vprint(FILE* f, const text_style& ts, string_view fmt,
|
inline void vprint(FILE* f, const text_style& ts, string_view fmt,
|
||||||
|
@ -143,7 +143,7 @@ FMT_END_NAMESPACE
|
|||||||
#ifndef FMT_USE_USER_LITERALS
|
#ifndef FMT_USE_USER_LITERALS
|
||||||
// EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs.
|
// EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs.
|
||||||
# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION || \
|
# 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)
|
(!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480)
|
||||||
# define FMT_USE_USER_LITERALS 1
|
# define FMT_USE_USER_LITERALS 1
|
||||||
# else
|
# else
|
||||||
@ -3807,8 +3807,8 @@ template <typename Char> struct udl_arg {
|
|||||||
return {str, std::forward<T>(value)};
|
return {str, std::forward<T>(value)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS
|
# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||||
#endif // FMT_USE_USER_LITERALS
|
#endif // FMT_USE_USER_LITERALS
|
||||||
|
|
||||||
template <typename Char> struct format_handler {
|
template <typename Char> struct format_handler {
|
||||||
parse_context<Char> parse_ctx;
|
parse_context<Char> parse_ctx;
|
||||||
@ -3857,7 +3857,6 @@ template <typename Char> struct format_handler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// DEPRECATED!
|
// DEPRECATED!
|
||||||
// Use vformat_args and avoid type_identity to keep symbols short.
|
|
||||||
template <typename Char = char> struct vformat_args {
|
template <typename Char = char> struct vformat_args {
|
||||||
using type = basic_format_args<buffered_context<Char>>;
|
using type = basic_format_args<buffered_context<Char>>;
|
||||||
};
|
};
|
||||||
@ -4349,8 +4348,7 @@ template <typename OutputIt, typename Locale,
|
|||||||
detail::is_locale<Locale>::value)>
|
detail::is_locale<Locale>::value)>
|
||||||
auto vformat_to(OutputIt out, const Locale& loc, string_view fmt,
|
auto vformat_to(OutputIt out, const Locale& loc, string_view fmt,
|
||||||
format_args args) -> OutputIt {
|
format_args args) -> OutputIt {
|
||||||
using detail::get_buffer;
|
auto&& buf = detail::get_buffer<char>(out);
|
||||||
auto&& buf = get_buffer<char>(out);
|
|
||||||
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
|
detail::vformat_to(buf, fmt, args, detail::locale_ref(loc));
|
||||||
return detail::get_iterator(buf, out);
|
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_EXPORT
|
||||||
|
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
#ifdef FMT_HEADER_ONLY
|
#ifdef FMT_HEADER_ONLY
|
||||||
|
@ -147,8 +147,8 @@ FMT_API std::system_error vwindows_error(int error_code, string_view format_str,
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
auto windows_error(int error_code, string_view message,
|
auto windows_error(int error_code, string_view message, const T&... args)
|
||||||
const T&... args) -> std::system_error {
|
-> std::system_error {
|
||||||
return vwindows_error(error_code, message, vargs<T...>{{args...}});
|
return vwindows_error(error_code, message, vargs<T...>{{args...}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,25 +148,14 @@ constexpr auto streamed(const T& value) -> detail::streamed_view<T> {
|
|||||||
return {value};
|
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>
|
FMT_EXPORT template <typename Char>
|
||||||
void vprint(std::basic_ostream<Char>& os,
|
void vprint(std::basic_ostream<Char>& os,
|
||||||
basic_string_view<type_identity_t<Char>> fmt,
|
basic_string_view<type_identity_t<Char>> fmt,
|
||||||
typename detail::vformat_args<Char>::type args) {
|
typename detail::vformat_args<Char>::type args) {
|
||||||
auto buffer = basic_memory_buffer<Char>();
|
auto buffer = basic_memory_buffer<Char>();
|
||||||
detail::vformat_to(buffer, fmt, args);
|
detail::vformat_to(buffer, fmt, args);
|
||||||
if (detail::write_ostream_unicode(os, {buffer.data(), buffer.size()})) return;
|
if (!detail::write_ostream_unicode(os, {buffer.data(), buffer.size()}))
|
||||||
detail::write_buffer(os, buffer);
|
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) {
|
void print(std::ostream& os, format_string<T...> fmt, T&&... args) {
|
||||||
fmt::vargs<T...> vargs = {{args...}};
|
fmt::vargs<T...> vargs = {{args...}};
|
||||||
if (FMT_USE_UTF8) return vprint(os, fmt, vargs);
|
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
|
FMT_EXPORT
|
||||||
|
@ -44,18 +44,6 @@ template <typename T> class is_set {
|
|||||||
!std::is_void<decltype(check<T>(nullptr))>::value && !is_map<T>::value;
|
!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
|
// C array overload
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
auto range_begin(const T (&arr)[N]) -> const T* {
|
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.
|
// Member function overloads.
|
||||||
template <typename T>
|
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>
|
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
|
// ADL overloads. Only participate in overload resolution if member functions
|
||||||
// are not found.
|
// are not found.
|
||||||
@ -115,12 +107,11 @@ struct has_mutable_begin_end<
|
|||||||
// SFINAE properly unless there are distinct types
|
// SFINAE properly unless there are distinct types
|
||||||
int>> : std::true_type {};
|
int>> : std::true_type {};
|
||||||
|
|
||||||
|
template <typename T, typename _ = void> struct is_range_ : std::false_type {};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_range_<T, void>
|
struct is_range_<T, void>
|
||||||
: std::integral_constant<bool, (has_const_begin_end<T>::value ||
|
: std::integral_constant<bool, (has_const_begin_end<T>::value ||
|
||||||
has_mutable_begin_end<T>::value)> {};
|
has_mutable_begin_end<T>::value)> {};
|
||||||
# undef FMT_DECLTYPE_RETURN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// tuple_size and tuple_element check.
|
// tuple_size and tuple_element check.
|
||||||
template <typename T> class is_tuple_like_ {
|
template <typename T> class is_tuple_like_ {
|
||||||
|
Reference in New Issue
Block a user