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: docopt::value to provide a represent method rather than overloading operator<< for std::ostream #135

Open
RuijieYu opened this issue Jun 24, 2020 · 1 comment

Comments

@RuijieYu
Copy link

Some background information: I was trying to use fmt alongside docopt, but as far as I am aware the parsed values cannot be "unconditionally" converted to string-like objects; docopt::value::toXXXX functions throw when the type don't match, and the operator<< overload requires that I use std::ostream (and std::stringstream), which is not an easy one-line solution.

It would be ideal if in the implementation instead of overloading operator<<, a noexcept version of represent function is provided that converts the underlying value with whatever type into a string-like object. Then if providing an operator<< is absolutely necessary, mark the overload inline that simply calls represent.

@jaredgrubb
Copy link
Member

So you are asking to have the to-string functionality be a member function rather than a global? Would 'represent' return a std::string? One benefit of << is that it doesn't require the creation of a string.

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