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

Inconsistency between fmt::to_string(_) and fmt::format("{}", _) #3684

Closed
avikivity opened this issue Oct 20, 2023 · 1 comment
Closed

Inconsistency between fmt::to_string(_) and fmt::format("{}", _) #3684

avikivity opened this issue Oct 20, 2023 · 1 comment

Comments

@avikivity
Copy link

#include <fmt/format.h>
#include <iostream>
#include <vector>
#include <fmt/ranges.h>

int main() {
    std::vector<std::string> x = { "abc", "def"};

    std::cout << fmt::format("{}", std::string("abc")) << std::endl;
    std::cout << fmt::format("{}", x) << std::endl;
    std::cout << fmt::to_string(x) << std::endl;
    return 0;
}

prints

abc
["abc", "def"]
[abc, def]

to_string() and fmt::format() return different results. I understood to_string() to be a simpler/faster fmt::format() with everything defaulted.

Why does the range formatter insert unnecessary escapes? Maybe it would be better to only insert them to make the output unambiguous.

@vitaut
Copy link
Contributor

vitaut commented Oct 28, 2023

Fixed in 19276d7, thanks for reporting. Conditional escaping is an interesting idea but it might be confusing to users and the format is pretty much fixed anyway.

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

2 participants