Why is it fmt::format_to(OutputIt, ...)
and not fmt::print(OutputIt, ...)
??
I'm currently familiarizing myself with {fmt}
, a / the modern C++ formatting library.
While browsing the API, I found the naming a bit disjoint, but given my little-to-no experience with the library (and my interest in API design), I would like to get behind these naming choices: (fmt core API reference)
- There's
fmt::format(...) -> std::string
which makes sense, it returns a formatted string. - Then we have
void fmt::print([stream, ] ...)
which also makes sense naming wise (certainly given theprintf
legacy). - But then we have
fmt::format_to(OutputIt, ...) -> OutputIt
which resembles, apart from the return type, whatprint
does with streams.
Now obviously, one can bike shed names all day, but here the question is not on why we have format
vs. print
(which is quite explainable to me), but why a function that clearly(?) behaves like the write-to-stream-kind has been bundled with the format_...
naming style.
So, as the question title already asks, is there a technical difference in how fmt::print(stream, ...)
behaves when formatting to a streams vs. how fmt::format_to(OutputIt, ...)
behaves when formatting to an output iterator?
Or was/is this purely a style choice? Also, given that the GitHube repo explicitly lists the fmt tag here, I was hoping that we could get a authoritative answer on this from the original API authors.