-
Notifications
You must be signed in to change notification settings - Fork 261
[SUGGESTION] Use std::format for string formatting if possible #133
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
Comments
Missclick, terribly sorry. With |
I like this suggestion and I'm all for using the best standard facilities and requiring C++20 as a baseline... but this means the reality of "C++20 as she is spoke," meaning the (large) subset of C++20 that is implemented and supported in at least the three major compilers. As a quick test to see how So I'm interested in using That said, this leads to a good question: What level of C++ support should cppfront take a hard dependency on? Informally I've been targeting the following, because I want Cpp2 code to be compilable with at least the latest version of the three major C++ compilers:
But perhaps I should raise the bar a little because not everyone can pick up the very latest version right away... maybe it should be
Taking And, well, now that we're using that example, this also means ignoring Apple Clang, which I've heard tends to lag and not always take all trunk features. Apple Clang is kind of important though, because Mac/iOS devs are a significant audience, so maybe it should be this to acknowledge that there are in practice two Clangs?
... but honestly I don't know how to evaluate that because I have a hard time finding the delta between Apple Clang and Clang, and IIUC you need to have a Mac to test with it (e.g., I don't see it on Godbolt). |
As I am a Mac user, I can help in evaluating that. |
GCC's current release, GCC 12, doesn't support
|
IMHO, since Cpp2 is still an experiment as of now, and as such no production code is expected to be written with it, we should not really worry about the minimal dependencies. By the time (and if) Cpp2 will be ready enough to be used in production, I would expect that the major compilers will support all facets of C++20. We already support C++20 modules, even though modules are not implemented by all compilers (as of current release versions). Finally, if we want to encourage idiomatic use of C++, we should be utilizing all utilities provided by STL, instead of inventing a competing standard. We could, for example, conditionally enable string interpolation only if Additionally, projects that cannot upgrade to the latest-and-greatest version of GCC, Clang or MSVC probably would not be using Cpp2 either. |
I understand, but I'm going to avoid conditionally supported features for now. Even for
Thanks! Perhaps the simplest would be to create another sister results directory beside If you'd like to do that, please just create a PR and I'd be happy to merge it. I would not be able to test with that directory or update it, so periodically if you could let me know if anything broke there that didn't break in the other ones that would be great. Actually that would also help fill another gap: I don't currently have checked in a test with Clang using libc++ (the current Thanks! |
I think this depends on a more important question about your plan. Will CppFront stay a transpiler from new syntax to existing C++? How will things like metaclasses and compile-time blocks with code injection be translated? By waiting until the major compilers implement it first in standard C++ syntax? Because if so, I think this project would benefit from just using whichever compiler is most advanced at any given point. Unless you've thought it through and found a way to implement those features using current C++ syntax? (After all, macros + templates are Turing complete at compile time - so there's bound to be a possible implementation). |
I plan to implement those in cppfront via support for inspecting and changing the parse tree.
No, in part because one goal of cppfront is to implement proposals for ISO C++ in a simpler syntax and compiler. For example, in cppfront I've already implemented
We don't have to resort to that (mostly)... :) there are a few macros in |
Since we have
std::format
as part of STL now since C++20, I would expect people to be implementing specializations forstd::formatter
in Cpp1. As such, in my opinion it would be beneficial to usestd::format
for to-string conversion (or string formatting itself) if possible.It would avoid the need to duplicate string conversion code (only a specialization of
std::formatter
will be needed), and could improve performance, sincestd::format
is more efficient than string concat. It would also prevent creation of yet another string formatting standard.The text was updated successfully, but these errors were encountered: