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

to_string() doesn't work with custom format_as()? #3545

Closed
usefulcat opened this issue Jul 21, 2023 · 1 comment
Closed

to_string() doesn't work with custom format_as()? #3545

usefulcat opened this issue Jul 21, 2023 · 1 comment

Comments

@usefulcat
Copy link

I thought that fmt::to_string() would use custom format_as() overloads, but it seems not to. Is this expected?

Using gcc13, c++20
https://godbolt.org/z/3fo53PoYW

#include <cassert>
#include <fmt/format.h>

enum class MyEnum : char {
    one = '1',
    two = '2',
    three = '3'
};

char format_as(MyEnum e) {
    return static_cast<char>(e);
}

int main() {
    assert(fmt::format("{}", MyEnum::one) == "1"); // compiles and works as expected
    assert(fmt::to_string(MyEnum::one) == "1");    // does not compile
    return 0;
}
@vitaut
Copy link
Contributor

vitaut commented Jul 22, 2023

This is not supported at the moment but a PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants