add missing make_printf_args and make_wprintf_args to printf.h
add minimal test for make_printf_args and make_wprintf_args to printf-test.cc
This commit is contained in:
parent
6c95fb3562
commit
b643520c52
@ -581,6 +581,33 @@ struct printf_context {
|
||||
typedef basic_format_args<printf_context<internal::buffer>::type> printf_args;
|
||||
typedef basic_format_args<printf_context<internal::wbuffer>::type> wprintf_args;
|
||||
|
||||
typedef printf_context<internal::buffer>::type printf_char_context;
|
||||
typedef printf_context<internal::wbuffer>::type printf_wchar_context;
|
||||
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs an `~fmt::format_arg_store` object that contains references to
|
||||
arguments and can be implicitly converted to `~fmt::printf_args`. `Context`
|
||||
can be omitted in which case it defaults to `~fmt::printf_char_context`.
|
||||
\endrst
|
||||
*/
|
||||
template<typename Context=printf_char_context, typename... Args>
|
||||
inline format_arg_store<Context, Args...>
|
||||
make_printf_args(const Args &... args) { return {args...}; }
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs an `~fmt::format_arg_store` object that contains references to
|
||||
arguments and can be implicitly converted to `~fmt::wprintf_args`. `Context`
|
||||
can be omitted in which case it defaults to `~fmt::printf_wchar_context`.
|
||||
\endrst
|
||||
*/
|
||||
template<typename Context = printf_wchar_context, typename... Args>
|
||||
inline format_arg_store<Context, Args...>
|
||||
make_wprintf_args(const Args &... args) { return {args...}; }
|
||||
|
||||
|
||||
template <typename S, typename Char = FMT_CHAR(S)>
|
||||
inline std::basic_string<Char>
|
||||
vsprintf(const S &format,
|
||||
|
||||
@ -518,3 +518,19 @@ void check_format_string_regression(fmt::string_view s, const Args&... args) {
|
||||
TEST(PrintfTest, CheckFormatStringRegression) {
|
||||
check_format_string_regression("%c%s", 'x', "");
|
||||
}
|
||||
|
||||
|
||||
TEST(PrintfTest, VSPrintfMessageExample) {
|
||||
EXPECT_EQ(
|
||||
"[42] something happened",
|
||||
fmt::vsprintf(
|
||||
"[%d] %s happened", fmt::make_printf_args( 42, "something" ) ) );
|
||||
}
|
||||
|
||||
|
||||
TEST(PrintfTest, VSPrintfWMessageExample) {
|
||||
EXPECT_EQ(
|
||||
L"[42] something happened",
|
||||
fmt::vsprintf(
|
||||
L"[%d] %s happened", fmt::make_wprintf_args( 42, L"something" ) ) );
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user