What to expect with C++20

Pages: 123
You may actually be better-served by learning C++ on your own (though I wouldn't say the same about computer science in general). From what I've seen (and even if my experience is limited, I've been doing the newb-helping thing for years now), C++ is frequently mistaught in formal settings. It's not even an issue of a class using C++11 when they could be using C++17, it's them teaching C++98 as if it was just a set of helpful extensions bolted onto C, and actively eschewing best practices as determined by the people who actually use the language.

C++20 is only going to make that situation worse, as adoption begins. For instance, I betcha people are still going to be taught templates as an "advanced" feature, and never taught concepts.

-Albatross
C++20 is only going to make that situation worse

In my experience each new iteration of C++ still is treated by a lot of academic environments as "advanced," only to be used after long slogs through old code.

More than a few questions asked here still rely on using the C library, rand() for example, instead of using "modern" C++. Or standard fixed arrays instead of a C++ container.

Or manually managing memory with raw pointers instead of smart pointers.

I get the impression that the instructors and/or the course material is outdated and no one wants to take the time and effort to upgrade.

Learning C++ on my own is both helpful and a curse. I get to go at my own pace, wander off into "the weeds" with some aspect I find interesting/useful, etc.

But I also don't have the grounding for debugging faulty apps as well as a lot of the other framework for being a professional. I know I have deficits in my understanding of C++, but just how broad and deep that lack is I really DO NOT know.

Being self-taught makes it hard at times to explain something beyond a simple "for dummies" approach. A good example of that is here:

http://www.cplusplus.com/forum/beginner/259867/#msg1129280
Last edited on
In my experience each new iteration of C++ still is treated by a lot of academic environments as "advanced," only to be used after long slogs through old code.

Anything that does something mildly convenient is "advanced" to them.

Last professor sucked at teaching C++, I suspect mainly because he was coding in C most of the time. He showed us a neural network he coded, but it was clearly written in C.
Ok, just what the hell is the spaceship operator (<=>) supposed to do? And how will using it improve code written with it?

I've looked around the internet and can't seem to find any non-technical sources to 'splain this at a Lucy Ricardo For Dummies level.
https://devblogs.microsoft.com/cppblog/simplify-your-code-with-rocket-science-c20s-spaceship-operator/

You aren't likely to get a better explanation than this.

The operator itself returns the equivalent (typed, in C++, to qualify the kind of equivalence being applied) of <0, ==0, and >0. Consider how strcmp() returns, or how qsort() works, to understand the basic principle.

What remains in C++'s implementation is types to deal with the concepts of equivalence vs identity, or strict vs weak ordering.

Hope this helps.
In the end, it is a construct to help the programmer write correct code, the first time, every time.
That MS Devblog is marginally less techno-gibberish than other links I had found before. Reading it through multiple times might help.

I guess I will just have to wait for C++2a to become C++20. Example(s) on how to use at cppreference will be sure to follow.

Thanks for the help, even if I don't understand most of what it says. :)
Oh my, the link you gave had another link. I followed that link and *DOINK! Lightbulb!* some understanding! Not all the way, but some light and less mud.

https://blog.tartanllama.xyz/spaceship-operator/

Interesting how C++2a is changing operator== as well.

*SIGH* and I still haven't scratched more than just the surface of C++17.

:O)
The spaceship operator doesn't really change how you write regular code. It's just a tool to make it easier to implement consistent comparison operators for a class.

If you implement your own operator<=> it will allow your class to be compared using <, >, <= and =>.

If you implement your own operator== it will allow your class to be compared using both == and != (this is also new in C++20).

These operators can also be defaulted (e.g. auto operator<=>(const MyClass&) = default;).

A defaulted operator== just calls == on the data members in the order they appear in the class definition.

A defaulted operator<=> calls <=> on the data members and it also provides a defaulted operator== as described above.

Also note that C++20 can reverse the arguments to these operators so if you want to allow comparison between two different types you no longer need to provide two versions (one for each order, A == B, B == A).
Of course things like concepts and modules will be worth trying out, but I'm definitely going to use std::source_location.

https://en.cppreference.com/w/cpp/utility/source_location
I've always disliked using __LINE__ and __FUNC__ macros, and soon I won't have to!

I like how the parts of volatile that made no sense have been deprecated. (I still would be lying if I said I understood it)
https://www.youtube.com/watch?v=KJW_DLaVXIY

constexpr for std::string also sounds great.

The https://en.cppreference.com/w/cpp/header/bit header looks promising, allowing us to directly write things like popcount and base-2 functions instead of having to rely on the compiler to be smart and do it for us, along with things like bit_cast.
I'm happy I can write function templates without the pointless template keyword, as void f(auto x)

Ok, I like that syntax. Lots cleaner. As well as IMO an intuitive use of auto.

IF writing a header file with that form of a template, will that function still be "required" to be declared and defined in the header file? Or can the function definition be in a source translation unit file?
IF writing a header file with that form of a template, will that function still be "required" to be declared and defined in the header file? Or can the function definition be in a source translation unit file?

It's just a new syntax. The way templates work is still the same so you still have to define them in the header.
Thank you, Peter87. I thought it would be the same, but it never hurts to ask.
C++23 will add partial or full networking libraries, and the standard after it will finalize networking libs if not fully implemented in C++23.

For C++20 I cant wait for modules and unit testing framework.
modules will make compile time 5 times faster, and unit testing makes me happy to avoid 3rd party frameworks.

concepts, it looks like only library implementors will truly benefit from them, hardly you will need them in regular projects.

part of the gsl library will become standard (not sure what exactly) would like to hear.
What's this about unit testing? There's some form of standardization to make that easier?
@Ganado
Interesting, I just looked again on what will be in C++20, and there is mention of "feature testing" macros, but not unit testing :/

Sorry for misinformation, I find out about this possible hoax here:
http://www.cplusplus.com/forum/general/265680/

I'm still not sure what does that mean but the cast refers to this non official boost unit test header (which is not C+20 standard, it just uses C++20 features)
https://github.com/boost-experimental/ut
Okay, thank you for the clarification. That boost::ut does look cool though.
Sorry for misinformation, I find out about this possible hoax here ...

It's not a hoax. A "C++ library" is not necessarily a standard library. A "C++20 library" is just a library that requires C++20.

modules will make compile time 5 times faster

Are you sure?

concepts, it looks like only library implementors will truly benefit from them, hardly you will need them in regular projects.

If it leads to better error messages it will be something that the users of the libraries can also benefit from.

part of the gsl library will become standard (not sure what exactly) would like to hear.

I'm no expert on GSL but std::string_view, which seems pretty much the same as gsl::string_span, was added already in C++17. C++20 will add std::span, replacing gsl::span. The Expects/Ensures macros were supposed to be replaced with contracts but that feature didn't make it into C++20.
modules will make compile time 5 times faster
Are you sure?

Absolutely sure about that, I watched the video somewhere on youtube, and B. Stroustrup him self said that in the video. (not sure did he say 5x or 6x faster).

If I recall correctly he was talking about no need to recompile same code over and over again due to dependencies or code changes (not sure exactly), because modules do not need to be recompiled, and that's what will make compilation faster.

I think it was this video:
https://www.youtube.com/watch?v=u_ij0YNkFUs
Pages: 123