mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Parameterize format_to on string type (#880)
This commit is contained in:
@ -3501,11 +3501,14 @@ inline OutputIt vformat_to(
|
|||||||
fmt::format_to(std::back_inserter(out), "{}", 42);
|
fmt::format_to(std::back_inserter(out), "{}", 42);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename OutputIt, typename... Args>
|
template <typename OutputIt, typename String, typename... Args>
|
||||||
inline OutputIt format_to(OutputIt out, string_view format_str,
|
inline OutputIt format_to(OutputIt out, const String &format_str,
|
||||||
const Args &... args) {
|
const Args &... args) {
|
||||||
return vformat_to(out, format_str,
|
internal::check_format_string<Args...>(format_str);
|
||||||
make_format_args<typename format_context_t<OutputIt>::type>(args...));
|
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>
|
template <typename OutputIt>
|
||||||
|
@ -682,6 +682,12 @@ TEST(FormatToTest, Format) {
|
|||||||
EXPECT_EQ("part1part2", s);
|
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) {
|
TEST(FormatToTest, FormatToNonbackInsertIteratorWithSignAndNumericAlignment) {
|
||||||
char buffer[16] = {};
|
char buffer[16] = {};
|
||||||
fmt::format_to(buffer, "{: =+}", 42.0);
|
fmt::format_to(buffer, "{: =+}", 42.0);
|
||||||
|
Reference in New Issue
Block a user