4 ms·
Yes, already since C++20. But if you really would have wanted to change your mind, you could’ve found out easily.
by Longhanks 3y ago
Yes, already since C++20. But if you really would have wanted to change your mind, you could’ve found out easily.
- LordDragonfang 3y ago>Already since C++20 ...Or phrased another way, they finally added them in the latest spec (which the majority of C++ devs aren't even using yet)
- deleted 3y ago[deleted]
- akhosravian 3y agoC++23 was finalized nearly six months ago so it is not correct to call C++20 the “latest spec”.
- LordDragonfang 3y agoI should have said the "latest standard", not "spec", if we're being technical. But EVERY bit of official material is very clear about asserting that C++23 is still a preview/in-progress, not a standard. Saying otherwise is, strictly speaking, incorrect. https://isocpp.org/std/the-standard https://isocpp.org/std/the-standard https://www.iso.org/standard/79358.html https://www.iso.org/standard/79358.html https://github.com/cplusplus/draft/blob/main/papers/n4951.md https://github.com/cplusplus/draft/blob/main/papers/n4951.md And quite frankly, what matters to devs is what tooling supports the specification without special configuration, and the answer is "basically none". Not a single compiler fully supports it. https://en.cppreference.com/w/cpp/compiler_support/23 https://en.cppreference.com/w/cpp/compiler_support/23 Also, side note, I'd be surprised if more than a third of C++ devs were even using C++20, based on last year's numbers showing only ~25% adoption: https://www.jetbrains.com/lp/devecosystem-2022/cpp/ https://www.jetbrains.com/lp/devecosystem-2022/cpp/
- SubjectToChange 3y agofmt has been available for years and it works with ridiculously old compilers. It’s great to have it standardized but it’s not a new capability that C++ didn’t already have.
- psychphysic 3y agoMost people don't have time to spend repeatedly checking for features in languages they don't use.
- Longhanks 3y agoIf people don’t have time to keep up with a languages updates (which, in case of C++, is currently _once_ every three years), then they don’t have time to complain about the lack of features, either. This one had the time to complain and just didn’t want to bother typing "c++ string formatting", which would have been fewer keystrokes than the comment complaining. On DuckDuckGo, the very first result for "c++ string formatting" is the exact thing this person was complaining about.
- psychphysic 3y agoBut then he'd have missed out on your conversational effervescence.
- nuxi 3y agoOP asked about “f-strings like python has”, which is different from plain std::format().
- JonChesterfield 3y agoGoogle finds https://stackoverflow.com/questions/62781161/is-it-possible-to-format-strings-in-c-like-pythons-f-strings https://stackoverflow.com/questions/62781161/is-it-possible-... which is a portal to horrors with the answer "no"
- nuancebydefault 3y agoThat about wanting to change mind... it touches a string! Somehow the let-downs must have been too much for me at a certain point in time. That being said, I'm curious to find out right now. Edit... no such thing found as string interpolation in cpp, at least not in my first 4 search hits. I'll crawl back.
- Conscat 3y agoString interpolation is currently blocked by: - template-function parameters (NTTPs with a function parameter syntax rather than a template parameter syntax, tentatively spelled as `void foo(template int constant){}` ) - Scalable reflection, in combination with expansion statements (likely in C++26, spelled `template for (auto& e : array) {}` ) which would allow you to write an arbitrary parser for the template string into real C++ code. Reflection targets C++29. Syntax2 already supports string interpolation as a special compiler feature.
- coldtea 3y agostd::string formatted_str = std::format( "My name is {} and my favorite number is {}", name, num);
- 0xffff2 3y agoThat's really nothing like python strings, which for the same string would be formatted_str = f"My name is {name} and my favorite number is {num}" The function call I could forgive, but the the ability to embed arbitrary python expressions into the f-string directly is a huge readability win IMO.
- interroboink 3y agoMeanwhile Perl's over here like "we had this in the 90s!" (: eg: perl -e '$x="AAA"; print "lowercase: ${\( lc($x) )}\n"'
- gpderetta 3y ago
- paulddraper 3y agoYou misunderstand. C++20 added std::format [1], similar to Python's str.format [2] (~2010). But OP said f-strings [3] (2016) which is string interpolation, a language-level feature. C++ does not have string interpolation. Not massively important, but IMO quite handy for inline code, e.g. SQL parameterization. [1] https://en.cppreference.com/w/cpp/utility/format/format https://en.cppreference.com/w/cpp/utility/format/format [2] https://docs.python.org/3/library/stdtypes.html#str.format https://docs.python.org/3/library/stdtypes.html#str.format [3] https://docs.python.org/3/reference/lexical_analysis.html#f-strings https://docs.python.org/3/reference/lexical_analysis.html#f-...