Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: fmt::to_string #326

Closed
netheril96 opened this issue May 15, 2016 · 5 comments
Closed

Feature request: fmt::to_string #326

netheril96 opened this issue May 15, 2016 · 5 comments

Comments

@netheril96
Copy link

Basically the same as std::to_string. It should not be hard to implement as it is functionally equivalent to fmt::format("{}", XXX). Reasons that I would like to use fmt::to_string in lieu of std::to_string:

  • std::to_string is not available on C++03.
  • std::to_string is horrendously slow on some implementations. Last time I checked, MSVC internally creates a stringstream for every std::to_string call.
@vitaut
Copy link
Contributor

vitaut commented May 15, 2016

Good idea. It can even be implemented in a more efficient way than fmt::format("{}", XXX), something like:

template <typename T>
std::string to_string(const T &value) {
  fmt::MemoryWriter w;
  w << value;
  return w.str();
}

Or, even better, writing directly to std::string with a writer described in #292.

vitaut added a commit that referenced this issue May 19, 2016
@vitaut
Copy link
Contributor

vitaut commented May 19, 2016

Done in b6c0cf9. fmt::to_string is defined in a separate header, fmt/string.h.

@vitaut vitaut closed this as completed May 19, 2016
@vitaut
Copy link
Contributor

vitaut commented May 19, 2016

It's documented here: http://fmtlib.net/dev/api.html#_CPPv2N3fmt9to_stringERK1T

@alabuzhev
Copy link
Contributor

Could you please add fmt::to_wstring as well?

@vitaut
Copy link
Contributor

vitaut commented Aug 27, 2017

@alabuzhev Would you be willing to submit a pull request along the lines of b6c0cf9? =)

neheb added a commit to neheb/gerbera that referenced this issue Jan 31, 2021
The former is faster. More info: fmtlib/fmt#326

Signed-off-by: Rosen Penev <[email protected]>
whyman pushed a commit to gerbera/gerbera that referenced this issue Feb 1, 2021
The former is faster. More info: fmtlib/fmt#326

Signed-off-by: Rosen Penev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants