CppCon 2018: Herb Sutter “Thoughts on a more powerful and simpler C++ (5 of N)”

preview_player
Показать описание


Perhaps the most important thing we can do for C++ at this point in its evolution is to make sure we preserve its core strengths while also directing its evolution in ways that make it simpler to use. That is my own opinion at least, so this talk starts with a perspective question: What “is C++,” really? The language continues to evolve and change; as it does so, how can we be sure we’re picking C++ evolutionary improvements that not only don’t lose its “C++-ic” qualities, but make it a better C++ than ever?

At recent CppCons, I’ve spoken about several of my own personal C++ evolution efforts and experiments, and why I think they’re potentially important directions to explore for making C++ both more powerful and also simpler to use. The bulk of the talk is updates on two of these:

1. Lifetime and dangling: At CppCon 2015, Bjarne Stroustrup and I launched The C++ Core Guidelines in our plenary talks. In my part starting at 29:06, I gave an early look at my work on the Guidelines “Lifetime” profile, an approach for diagnosing many common cases of pointer/iterator dangling at compile time, with demos in an early MSVC-based prototype. For this year’s CppCon, I’ll cover what’s new, including:
• use-after-move diagnoses
• better support for the standard library out of the box without annotation
• more complete implementations in two compilers: in MSVC as a static analysis extension, and in a Clang-based implementation that is efficient enough to run during normal compilation
• the complete 1.0 Lifetime specification being released on the Guidelines’ GitHub repo this month

I’ll summarize the highlights but focus on what’s new, so I recommend rewatching that talk video as a refresher for background for this year’s session.

2. Metaclasses: In my CppCon 2017 talk, I gave an early look at my “metaclasses” proposal to use compile-time reflection and compile-time generation to make authoring classes both more powerful and also simpler. In this case, “simpler” means not only eliminating a lot of tedious boilerplate, but also eliminating many common sources of errors and bugs. For this year, we’ll cover what’s new, including:
• an update on the Clang-based implementation, which now supports more use cases including function parameter lists
• new examples, including from domains like concurrency
• an updated P0707 paper, with more links to working examples live on Godbolt, being posted in the next few weeks for the pre-San Diego committee mailing

Herb Sutter
Microsoft
Author, and chair of the ISO C++ committee.


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

Impressive talk, in my opinion he is the one with a greater vision in the committee, looking forward for the metaclasses

benhur
Автор

I bet Herb has a huge walk-in closet to display his impressive Hawaiian shirt collection.

vertigo
Автор

Very excited about metaclasses. I think it's the most powerful language feature introduced since templates.

acmdz
Автор

Because metaclasses are tightly coupled to reflection and codegen, I'll just just say it. If the restrict(amp) compatible (aka. "static C++") statements of a function could be traversed via reflection, one could implement not just MOC-like tools, but C++AMP/SYCL-like compilers as ISO C++ libraries. Herb having designed C++AMP as well, that would be one less language extension to do again, something that would enable GPGPU within C++ as a library feature. I was told that the current reflection TS does not allow traversing private members either. Adding these two would solve most of the headaches HPC is suffering from, portability of code, vendor lock-in, API support, etc.

mateferencnagy-egri
Автор

C++ metaclass is going to be a killer feature. I think we probably will have it in the language by 2022-2024. I doubt other (mainstream) languages have this capability.

sivabudh
Автор

Great talk Herb!, I've seen Herbs talk about Metaclasses from last year and I really want to see this in C++.

Eldorante
Автор

Imagine not having reflection in 2021... a feature that should have been here for the last 10 years.

andreicirstea
Автор

The presentations are great as always. I just wish they wouldn't include that weird noisy music at the beginning.

Fetrovsky
Автор

So Herb came last year with a good syntax for metaclasses that could be improved and the C++ Commity walks in and made the syntax uglier, less readable and overly complex instead of making it better! Nice Job commity!

alfredomoreira
Автор

I'm still waiting for a new episode from CppCon 2018. Please upload a new one.

PixelPulse
Автор

I really like how C++ has evolved to such powerful language, but metaclasses syntax looks kind of weird to me

meinklavier
Автор

I have to say, last year Herb's syntax was so much more beautiful and straightforward. Current committee's syntax proposal sux, sorry.

nula
Автор

Herb, I don't know why you seem to need to explain why adding features makes the code simpler. Functions are like words that you add to the language. Imagine if every time you wanted to reference a coffee cup, you had to say "a small bucket made with an insulated material to prevent burning of the holder by the contents, which is expected to be hot, and probably is coffee." It's much quicker to just say "coffee cup", which does imply that the listener has some knowledge about what material the bucket would be composed, and it's size, but it's far more convient for the speaker, and I'd say the listener gets the benefit of parcing and processing the sentence much more quickly.

jaysistar
Автор

I like meta classes, image possibility to have meta class that can transform C++ class to object that is compatible with Python, PHP or Node engines.

edino
Автор

It will be hard first but it can be easier for us all...

TheLavaBlock
Автор

He really did a disservice to his argument by showing the child's play C# class declaration, and then the C++ attempt to emulate part of it partially with refrefs and angle brackets abound.

schulmastery
Автор

I googled "defun defun 3" like suggested actually and it came up with nothing. I am guessing the idea is that it replaces the defun macro with a function that returns the constant 3?

timseguine
Автор

Spotted an error at the 1h mark - the lock_guard should be using {}'s rather than ()'s to capture a lock to data1, otherwise it's a function call def and not what was wanted.

RachelMant
Автор

Compiler checks dangling pointers and null pointer. It must be a dream. Where is the paper of how this is implemented?

PixelPulse
Автор

Removing macros means making debugging harder, if no new language feature is added, that allows writing assert. I thought about a new type of parameter passing; pass by expression. The parameter is never evaluated until you use it in the function body. There should also be a way to get the source code of an expression-parameter to be used in a message.

I am using $ as a symbol for expressions, you evaluate it with $, as you dereference a pointer with *:

void assert(bool$ expr) {
if constexpr(DEBUG) {
if(!$expr) {
assertion_failed(expr.source, expr.file, expr.line);
}
}
}

assert(42 == 20+20+2);

An expression has a $ operator to be evaluated, the members source, file and line to contain debug information. As expressions are statically included in binary, the function needs to be inlined always, as you expect it with lambdas:

template<typename T>
void assert_f(T expr_func) {
if constexpr(DEBUG) {
if(!expr_func()) {
...
}
}
}

assert_f([]{ return 42 == 20+20+2; });

cmdlp