
Changes Between C++17 and C++20 - matt_d
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2131r0.html
======
cobbzilla
At the bottom of the page, I had to chuckle at:

Assorted snippets demonstrating C++20

    
    
        int main() {}

~~~
tandr
There is no return statement, although function is marked as `int`

~~~
colejohnson66
C and C++ explicitly permit this

~~~
tandr
I remember problems compiling this in older C++, circa 2000. Maybe was just a
compiler's "opinion"...

~~~
colejohnson66
Probably just a buggy implementation. The C _and_ C++ standards are explicit
that `main` return an int and only an int. _Never_ void. This has _always_
been the case. However, the `main` function is the only function where the
return statement _can_ be omitted. If it is omitted, it’s an implicit `return
0`.

------
jujodi
Can someone explain the purpose of "Three-way comparison (“spaceship”) and
defaulted comparisons"

>>>The value of the expression a <=> b describes which one of a < b, a == b,
and a > b is true.

A key part of this feature is that classes that provide this operator can have
all of the six traditional, binary relational operators defined implicitly.

~~~
johannes1234321
The primary purpose of this is reducing boilerplate code. For supporting
comparisons one currently has to implement a large set if functions. One for
each of <, >, <=, =>, != and ==. However many times the implementation of
those 6 functions is similar. Thus lots of code to write.

With operator<=> one can implement a single function and the compiler becomes
the smart one. When calling o1 < o2 or calling o1 >= o2 the compiler will do a
call to the single operator<=> and interpret the return value accordingly.

Notably less repitive typing for the type provider.

~~~
hak8or
What if you want to do an equality operation, but the greater than or less
than operators require lots of computation? If an object only defines the
space ship operator, then isn't it very likely that you will get a lot of
extra computation when all you care baout if the two objects are or aren't
equal to each other?

~~~
aw1621107
I believe programmers are still free to define specific operators in lieu of
the compiler-derived ones for such cases.

I found a blog post which raised similar concerns [0], and P1185 [1] proposes
some solutions. I don't know whether they made it into the standard, though.

[0]: [https://foonathan.net/2018/10/spaceship-
proposals/](https://foonathan.net/2018/10/spaceship-proposals/)

[1]: [http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2019/p118...](http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2019/p1185r1.html)

