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

Suggestion: Enrich the format API by exposing some elements of details #3191

Closed
lano1106 opened this issue Nov 17, 2022 · 1 comment
Closed
Labels

Comments

@lano1106
Copy link

lano1106 commented Nov 17, 2022

I wanted to support some sort of precision specifications without reinventing the wheel for my user defined formatter...

After having opened the hood to see how you were doing it. I ended up with:

    constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin())
    {
        auto it = ctx.begin(), end = ctx.end();

        if (it != end) {
            if (*it == 'm') {
                m_type = MAXIMUM;
                ++it;
            } else if (*it == '.') {
                m_type = CUSTOM;
                it = detail::parse_precision(it, end, Handler<ParseContext>{ctx, m_specs});
                if (it == end) return it;
            }
        }
        // Check if reached the end of the range:
        if (it != end && *it != '}') throw format_error("invalid format");
        // Return an iterator past the end of the parsed range:
        return it;
    }

I am pretty sure that a lot of people would appreciate if detail::parse_precision() and others would be easily available to them...

@vitaut
Copy link
Contributor

vitaut commented Nov 18, 2022

Thanks for the suggestion. This and related documentation improvements are already tracked in #2086 and will hopefully be addressed in one of the upcoming versions.

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

No branches or pull requests

2 participants