C++23’s Deducing this: what it is, why it is, how to use it
devblogs.microsoft.com
devblogs.microsoft.com
template <typename T>
struct optional {
// One version of value which works for everything
template <class Self>
constexpr auto&& value(this Self&& self) {
if (self.has_value()) {
return std::forward<Self>(self).m_value;
}
throw bad_optional_access();
}
The fact that I can read this and don't even find it that terrible is proof that C++ has permanently damaged my brain.mind you, i feel much the same regarding rust syntax.
[1] http://thbecker.net/articles/rvalue_references/section_08.ht...
This is just a conceptualisation, of course (rvalue definition is a little more subtle), but for me as a Lisp programmer it seems natural and intuitive. If you come from a different background or perspective I understand that it can seem weird — again, most languages are not as expressive.
The low level nature that is fundamental to C++, even when you are programming at a very high level, which you now conveniently can, is a consequence of it working hard to be a zero-cost-abstraction systems programming language, leads to issues like this one, or to some odd consequences of move constructors.
There are alternative points in the solution space. Compare it to go, which explicitly papers over some of these trade offs, making an opinionated choice instead, and being willing to embrace reduced expressive power (so there are some things you just can’t write in it). I don’t like go myself, but that doesn’t mean people who choose it are fools.
[1]: https://eli.thegreenplace.net/2014/perfect-forwarding-and-un... [2]: https://en.cppreference.com/w/cpp/language/reference#Forward...
Yes, it is, to be diplomatic, highly imperfect, but working to avoid breaking existing code is one reason C++ is so successful.
The standard could go as far as to say what <foobar> should provide and then leave it up to the implementation what the actual non-aliased keyword actually is: maybe it’s _Foobar or maybe it’s something else, the end user won’t know because you just use foobar after including <foobar>
Keyword are part of the compiler; libraries (header files, modules, what have you) are not.
It’s perfectly legit to write and use a program that doesn’t use anything in std::
I know this is a bit of an “angels on the head of a pin” position to take.
There is no product that is done, and keeps being used ad infinitum.
By the way, C23 just has been ratified, last COBOL standard is coming this year as well, and Fortran was last updated in 2018.
https://en.cppreference.com/w/c/23
Meanwhile C++ just added for loop scoped typedefs.
for (typedef int Points; Points points : pointsScored) {
std::cout << "Jokic scored " << points << '\n';
}https://thephd.dev/lambdas-nested-functions-block-expression...
https://thephd.dev/c-the-improvements-june-september-virtual...
https://thephd.dev/ever-closer-c23-improvements
Only a small overview, I lost the link to the PDF with the whole set of language proposals for C2X.
Note that in the time C++ had 5 updates, Python has had 10 releases and Java has had 14!