mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 20:18:49 +00:00
Parameterize format_to on string type (#880)
This commit is contained in:
parent
d66fa2216e
commit
e4ca37ccf6
@ -3501,11 +3501,14 @@ inline OutputIt vformat_to(
|
||||
fmt::format_to(std::back_inserter(out), "{}", 42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename OutputIt, typename... Args>
|
||||
inline OutputIt format_to(OutputIt out, string_view format_str,
|
||||
template <typename OutputIt, typename String, typename... Args>
|
||||
inline OutputIt format_to(OutputIt out, const String &format_str,
|
||||
const Args &... args) {
|
||||
return vformat_to(out, format_str,
|
||||
make_format_args<typename format_context_t<OutputIt>::type>(args...));
|
||||
internal::check_format_string<Args...>(format_str);
|
||||
typedef typename format_context_t<OutputIt, FMT_CHAR(String) >::type context_t;
|
||||
format_arg_store<context_t, Args...> as{args...};
|
||||
return vformat_to(out, basic_string_view< FMT_CHAR(String) >(format_str),
|
||||
basic_format_args<context_t>(as));
|
||||
}
|
||||
|
||||
template <typename OutputIt>
|
||||
|
@ -682,6 +682,12 @@ TEST(FormatToTest, Format) {
|
||||
EXPECT_EQ("part1part2", s);
|
||||
}
|
||||
|
||||
TEST(FormatToTest, WideString) {
|
||||
std::vector<wchar_t> buf;
|
||||
fmt::format_to(std::back_inserter(buf), L"{}{}", 42, L'\0');
|
||||
EXPECT_STREQ(buf.data(), L"42");
|
||||
}
|
||||
|
||||
TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) {
|
||||
char buffer[16] = {};
|
||||
fmt::format_to(buffer, "{: =+}", 42.0);
|
||||
|
Loading…
Reference in New Issue
Block a user