
C++20 Is Feature Complete; Here’s What Changes Are Coming - jandeboevrie
https://hackaday.com/2019/07/30/c20-is-feature-complete-heres-what-changes-are-coming/
======
ncmncm
This article might seem confusing.

That's because it is. There is hardly a paragraph in it that is wholly
correct, where they actually mean anything.

C++ itself is much easier to understand than the article.

The real purpose for all the constexpr-related apparatus, as well as much of
Concepts, is to make it much rarer that anybody needs to do "template
metaprogramming". Instead of writing Template Metaprograms to run at compile
time (a very strange functional pattern-matching language practically nothing
like C++) you can usually write ordinary C++ code.

Coroutines are a new flow control primitive showing up in lots of languages
lately. The C++ version is the same as the others.

The main benefit you will see from Concepts is overwhelmingly better error
messages when you misuse a library component, whether Standard or your own.

Modules is a big step toward enabling a modern build infrastructure, as
already seen in lots of newer languages that got benefit of hindsight.

All the old stuff is still there, because billions of lines of old code still
use it. You don't have to use it in new code, but it all still works.

The biggest difference between old and new C++ code is that good new code uses
value types more, and reference types less, making everything safer.

Coding modern C++ is overwhelmingly more fun than coding C++98 was, but it is
just as fast as ever, and better than ever for writing fast, powerful, nice-
to-use, no-compromise libraries.

~~~
hackandtrip
I got had to fight with template metaprogramming lately, and I can't be
happier than reading about this. Do you have any sources when one can learn in
a non-confusing way about this new stuff, especially Concepts?

~~~
favorited
If you're looking for a high-level example, the Wikipedia article one where a
function is constrained to only accept an argument which implements operators
"==" and "!=".

[https://en.wikipedia.org/wiki/Concepts_(C%2B%2B)](https://en.wikipedia.org/wiki/Concepts_\(C%2B%2B\))

------
gigatexal
I’m not a C++ dev. I took one class of it in college and even then it was 90%
C and only hit pointers and classes on the final unit.

But holy smokes this is not your grandmother’s C++, is it just me or is the
language trying to be all things to all people? It’s getting too big, no? I
mean how long do you have to be writing C++ code to fully master the language?
Or can you be a high level dev without ever touching the new features? I’m
assuming production codebases are likely still stuck on older versions of the
language and might never move on.

I hope golang doesn’t grow this large over time.

~~~
asauce
One of the worst interview questions I have had was "Rate your C++ knowledge
from 1 - 10".

I had just finished my second year of college, and although I felt fairly
confident in my C++ abilities I had no idea how to answer. I thought it would
be best to be honest and said "4" based on the subset of the huge language I
knew (honestly this rating was probably too high at the time!).

One of the interviewers was obviously unhappy with the answer, and was
unpleasant the rest of the interview. I have always wondered what they
expected from such an vague question.

~~~
ksec
>One of the worst interview questions I have had was "Rate your C++ knowledge
from 1 - 10".

>One of the interviewers was obviously unhappy with the answer, and was
unpleasant the rest of the interview. I have always wondered what they
expected from such an vague question.

I knew enough of C++ to know my knowledge on the subject is approximately
close to Zero.

Basically no one on earth knows C++, they mostly know a subset of it.

*C++ here referring to Modern C++, Pre 2000 era C++ was still manageable.

Edit: On that thought it seems to me every PL in 90s were all manageable.
Somewhere along the line things got ugly.

~~~
thechao
I _love_ asking this question! I almost always get “7” as an answer! Except
one notable time: the interviewee said, at first, “seven”... then he stops,
slowly makes eye-contact and says “no: 10.” Brilliant! Who does that!?

I’ve interviewed hundreds of candidates; HR has relayed to me that many
candidates requested that HR tell me that they loved being interviewed by me,
even though the interview was very, very hard; they say they were surprised to
learn things, and also happy I was so interested in them as s person.

This always made me happy; I had to sacrifice a teaching career to program.

~~~
farah7
Curious as to why you love asking this question? I wonder what data you are
trying to glean from this question. It's a very subjective question and
wouldn't surprise me at all if the number of years experience a candidate has
in that language is inversely proportional to the answer you're given.

I often get this question from recruiters hiring front end developers: From 1
to 10, how well do you know Javascript? I've given 8 for as long as I remember
but often I think to myself if the people who wrote the V8 engine are 10 by
default, there is no way in hell I'm even close to an 8.

~~~
arithma
A good self-rating strategy in an interview would be to try and percentile
yourself among the people based on your knowledge and try to justify it with
humility. C++ is huge, I expect I know more than 80% of the people due to
(years of experience, different kinds of projects, yada yada), but I feel i
have only been able to explore like 50% of the language so far (concretely
learn that is) and there’s more to learn like (1, 2, 3..) and probably more
that I might have missed completely.

~~~
thechao
It’s almost always 7. The actual question I ask is “rate yourself on a scale
from one to Bjarne”. Bjarne Stroustrup was the principle in the group I did my
PhD, and _he_ rates himself a 7, so when interviewees give ‘7’ as the answer,
it makes me laugh.

------
hawski
I am C++ developer by career and I am pretty much bashing the language all the
time. To preserve my sanity I like to use C in after-hours. However looking up
C++20 and the direction whole language is going I see there are things I would
really like to see in C, while preserving C simplicity. Standardized
attributes like [[fallthrough]] and others for functions seem nice. Anonymous
functions are nice. They look a bit ugly, but function pointers already look
even worse. It would not hurt to have modules and consteval functions in C,
but then one still needs templates to really ditch the preprocessor and that's
a tough one to solve.

Having said all that C++ is really in a need of a clean cut between legacy
features and the blessed way. Backwards compatibility is a noble cause, but
there is also the whole weight it pulls around. Maybe something like
[[deprecated]] attribute could be extended to handle more cases. Maybe C++
needs it's own "unsafe" block, something like

    
    
      [[unsafe]] {
        *((void*)0) = 0xDEAD;
      }
    

Essentially having an ability to clearly mark all those different styles of
different versions of C++ really. So that compiler could help you to control
it and in case of a green field project totally guide you to use only the most
modern idioms with an escape hatch. Of course the problem is that to help with
the complexity more complexity would have to be added.

I am a bit on the crossroads. From one side I start to see, that there is some
hope for C++. But on the other I feel like running away, especially since I'm
looking for a job. In no particular order: C, Rust, Java, Kotlin, Scheme,
Julia, Go, OCaml, Free Pascal, Swift, TypeScript, Lua/Terra, Zig.

I had a funny thing with C++. One project I worked on was used in the debug
version all the time, to be able to drop to debugger when needed. At that
point I started to wonder why not just use Java already, instead of trying to
do a manual Java and fail at it.

------
empyrical
Despite the slight differences they have from the C99 version of them, I'm
pretty happy to see designated initializers in C++20

------
ilaksh
Sounds amazing. Anyone have code examples that integrate a lot of the newer
stuff?

Dumb question. Why isn't omitting 'return' always an error in gcc rather than
just a warning?

~~~
plorkyeran
int foo() { bar(); } is a perfectly well-formed function as long as bar()
never returns. Allowing this without requiring bar() to be annotated as
noreturn is generally considered a mistake, but correcting it would break
existing valid programs.

~~~
ComputerGuru
C++17 already made backward compatibility a non-goal (within reason,
obviously) and broke previously valid programs.

~~~
ComputerGuru
I don’t care that my previous comment post has been downvoted, but I do want
to clarify that I wasn’t being facetious; C++17 removes a number of old
features and constructs that had been previously deprecated and there exist
programs that compiled under C++14 that need non-trivial changes to compile
under C++17.

------
Ididntdothis
Looks pretty good. But I don’t understand why they don’t do string
interpolation like C# and others do.

“I= {I}”

Is much better and less error prone than

“I= {}”, I

Or am I missing something?

~~~
plorkyeran
The format library is a pre-existing library which is being standardized.
String interpolation cannot be implemented in a library, and requires language
extensions. Perhaps they should have done that instead, but that's a
significantly more complicated task than merely adopting something that's
already well tested and proven (and even that was far from trivial).

~~~
hawski
I am not necessarily opposing string interpolation as a language feature, but
I have an idea how could it work as a library. Implement string suffix and
overload comma operator or overload reminder operator. It would look like
this:

    
    
      "Hello {} {}!"i, 2, "worlds"
    

Or with reminder operator as in Python:

    
    
      "Hello {} {}!"istr % istr(2, "worlds")
    

But yeah, enough of this.

------
lousken
I've had C++98 at school, but how would I learn C++17? Scott Meyers wrote
C++14 but he retired from C++ development so what are the best alternatives?

~~~
antisemiotic
Changes from c++14 to c++17 are nowhere near as dramatic as c++98 to c++11, so
you can go with Scott Meyers and fill in the gaps from cppreference.com, for
example.

