Commit e4ca37cc authored by Victor Zverovich's avatar Victor Zverovich

Parameterize format_to on string type (#880)

parent d66fa221
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment