mirror of
https://github.com/fmtlib/fmt.git
synced 2025-03-15 16:20:59 +00:00
Simplify API
This commit is contained in:
parent
9998f66f8c
commit
85793a18cd
27
fmt/format.h
27
fmt/format.h
@ -1443,9 +1443,6 @@ class format_arg_store {
|
||||
// If the arguments are not packed, add one more element to mark the end.
|
||||
std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)> data_;
|
||||
|
||||
template <typename ...A>
|
||||
friend format_arg_store<Context, A...> make_format_args(const A & ... args);
|
||||
|
||||
public:
|
||||
static const uint64_t TYPES = internal::make_type<Args..., void>();
|
||||
|
||||
@ -1457,10 +1454,16 @@ class format_arg_store {
|
||||
|
||||
template <typename Context, typename ...Args>
|
||||
inline format_arg_store<Context, Args...>
|
||||
make_format_args(const Args & ... args) {
|
||||
make_xformat_args(const Args & ... args) {
|
||||
return format_arg_store<Context, Args...>(args...);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
inline format_arg_store<format_context, Args...>
|
||||
make_format_args(const Args & ... args) {
|
||||
return format_arg_store<format_context, Args...>(args...);
|
||||
}
|
||||
|
||||
/** Formatting arguments. */
|
||||
template <typename Context>
|
||||
class basic_format_args {
|
||||
@ -2271,7 +2274,7 @@ class SystemError : public internal::RuntimeError {
|
||||
*/
|
||||
template <typename... Args>
|
||||
SystemError(int error_code, CStringRef message, const Args & ... args) {
|
||||
init(error_code, message, make_format_args<format_context>(args...));
|
||||
init(error_code, message, make_format_args(args...));
|
||||
}
|
||||
|
||||
~SystemError() throw();
|
||||
@ -2494,7 +2497,7 @@ class BasicWriter {
|
||||
*/
|
||||
template <typename... Args>
|
||||
void write(BasicCStringRef<Char> format, const Args & ... args) {
|
||||
vwrite(format, make_format_args<basic_format_context<Char>>(args...));
|
||||
vwrite(format, make_xformat_args<basic_format_context<Char>>(args...));
|
||||
}
|
||||
|
||||
BasicWriter &operator<<(int value) {
|
||||
@ -3122,7 +3125,7 @@ class WindowsError : public SystemError {
|
||||
*/
|
||||
template <typename... Args>
|
||||
WindowsError(int error_code, CStringRef message, const Args & ... args) {
|
||||
init(error_code, message, make_format_args<format_context>(args...));
|
||||
init(error_code, message, make_format_args(args...));
|
||||
}
|
||||
};
|
||||
|
||||
@ -3146,7 +3149,7 @@ FMT_API void vprint_colored(Color c, CStringRef format, format_args args);
|
||||
template <typename... Args>
|
||||
inline void print_colored(Color c, CStringRef format_str,
|
||||
const Args & ... args) {
|
||||
vprint_colored(c, format_str, make_format_args<format_context>(args...));
|
||||
vprint_colored(c, format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
inline std::string vformat(CStringRef format_str, format_args args) {
|
||||
@ -3166,7 +3169,7 @@ inline std::string vformat(CStringRef format_str, format_args args) {
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline std::string format(CStringRef format_str, const Args & ... args) {
|
||||
return vformat(format_str, make_format_args<format_context>(args...));
|
||||
return vformat(format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
inline std::wstring vformat(WCStringRef format_str, wformat_args args) {
|
||||
@ -3177,7 +3180,7 @@ inline std::wstring vformat(WCStringRef format_str, wformat_args args) {
|
||||
|
||||
template <typename... Args>
|
||||
inline std::wstring format(WCStringRef format_str, const Args & ... args) {
|
||||
auto vargs = make_format_args<wformat_context>(args...);
|
||||
auto vargs = make_xformat_args<wformat_context>(args...);
|
||||
return vformat(format_str, vargs);
|
||||
}
|
||||
|
||||
@ -3194,7 +3197,7 @@ FMT_API void vprint(std::FILE *f, CStringRef format_str, format_args args);
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void print(std::FILE *f, CStringRef format_str, const Args & ... args) {
|
||||
vprint(f, format_str, make_format_args<format_context>(args...));
|
||||
vprint(f, format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
FMT_API void vprint(CStringRef format_str, format_args args);
|
||||
@ -3210,7 +3213,7 @@ FMT_API void vprint(CStringRef format_str, format_args args);
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void print(CStringRef format_str, const Args & ... args) {
|
||||
vprint(format_str, make_format_args<format_context>(args...));
|
||||
vprint(format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
|
||||
template <typename... Args>
|
||||
inline void print(std::ostream &os, CStringRef format_str,
|
||||
const Args & ... args) {
|
||||
vprint(os, format_str, make_format_args<format_context>(args...));
|
||||
vprint(os, format_str, make_format_args(args...));
|
||||
}
|
||||
} // namespace fmt
|
||||
|
||||
|
@ -172,7 +172,7 @@ public:
|
||||
|
||||
template <typename... Args>
|
||||
inline void print(CStringRef format_str, const Args & ... args) {
|
||||
vprint(format_str, make_format_args<format_context>(args...));
|
||||
vprint(format_str, make_format_args(args...));
|
||||
}
|
||||
};
|
||||
|
||||
|
10
fmt/printf.h
10
fmt/printf.h
@ -523,7 +523,7 @@ inline std::string vsprintf(CStringRef format,
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline std::string sprintf(CStringRef format_str, const Args & ... args) {
|
||||
return vsprintf(format_str, make_format_args<printf_context<char>>(args...));
|
||||
return vsprintf(format_str, make_xformat_args<printf_context<char>>(args...));
|
||||
}
|
||||
|
||||
inline std::wstring vsprintf(WCStringRef format,
|
||||
@ -535,7 +535,7 @@ inline std::wstring vsprintf(WCStringRef format,
|
||||
|
||||
template <typename... Args>
|
||||
inline std::wstring sprintf(WCStringRef format_str, const Args & ... args) {
|
||||
auto vargs = make_format_args<printf_context<wchar_t>>(args...);
|
||||
auto vargs = make_xformat_args<printf_context<wchar_t>>(args...);
|
||||
return vsprintf(format_str, vargs);
|
||||
}
|
||||
|
||||
@ -553,7 +553,7 @@ FMT_API int vfprintf(std::FILE *f, CStringRef format,
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline int fprintf(std::FILE *f, CStringRef format_str, const Args & ... args) {
|
||||
auto vargs = make_format_args<printf_context<char>>(args...);
|
||||
auto vargs = make_xformat_args<printf_context<char>>(args...);
|
||||
return vfprintf(f, format_str, vargs);
|
||||
}
|
||||
|
||||
@ -573,7 +573,7 @@ inline int vprintf(CStringRef format,
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline int printf(CStringRef format_str, const Args & ... args) {
|
||||
return vprintf(format_str, make_format_args<printf_context<char>>(args...));
|
||||
return vprintf(format_str, make_xformat_args<printf_context<char>>(args...));
|
||||
}
|
||||
|
||||
inline int vfprintf(std::ostream &os, CStringRef format_str,
|
||||
@ -596,7 +596,7 @@ inline int vfprintf(std::ostream &os, CStringRef format_str,
|
||||
template <typename... Args>
|
||||
inline int fprintf(std::ostream &os, CStringRef format_str,
|
||||
const Args & ... args) {
|
||||
auto vargs = make_format_args<printf_context<char>>(args...);
|
||||
auto vargs = make_xformat_args<printf_context<char>>(args...);
|
||||
return vfprintf(os, format_str, vargs);
|
||||
}
|
||||
} // namespace fmt
|
||||
|
@ -54,7 +54,7 @@ std::string custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
|
||||
|
||||
template <typename... Args>
|
||||
std::string custom_format(const char *format_str, const Args & ... args) {
|
||||
auto va = fmt::make_format_args<fmt::format_context>(args...);
|
||||
auto va = fmt::make_format_args(args...);
|
||||
return custom_vformat(format_str, va);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ std::string custom_vsprintf(
|
||||
|
||||
template <typename... Args>
|
||||
std::string custom_sprintf(const char *format_str, const Args & ... args) {
|
||||
auto va = fmt::make_format_args<CustomPrintfFormatter>(args...);
|
||||
auto va = fmt::make_xformat_args<CustomPrintfFormatter>(args...);
|
||||
return custom_vsprintf(format_str, va);
|
||||
}
|
||||
|
||||
|
@ -1559,7 +1559,7 @@ std::string vformat_message(int id, const char *format, fmt::format_args args) {
|
||||
|
||||
template <typename... Args>
|
||||
std::string format_message(int id, const char *format, const Args & ... args) {
|
||||
auto va = fmt::make_format_args<fmt::format_context>(args...);
|
||||
auto va = fmt::make_format_args(args...);
|
||||
return vformat_message(id, format, va);
|
||||
}
|
||||
|
||||
@ -1640,7 +1640,7 @@ void custom_vformat(fmt::CStringRef format_str, fmt::format_args args) {
|
||||
|
||||
template <typename... Args>
|
||||
void custom_format(const char *format_str, const Args & ... args) {
|
||||
auto va = fmt::make_format_args<fmt::format_context>(args...);
|
||||
auto va = fmt::make_format_args(args...);
|
||||
return custom_vformat(format_str, va);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user