CppCon 2017: Herb Sutter “Meta: Thoughts on generative C++”

Channel:CppCon · Length:1:47:44 · Published:2017-09-28 · Views:104541

Watch on YouTube

Summary

At CppCon 2017 Herb Sutter presents his work on evolving C++ through compile-time code generation, including metaclasses and reflection. The aim is to make the language both more powerful and simpler by letting programmers express intent directly.

Why HN recommends it

Praised as the best talk of CppCon 2017 and the key introduction to metaclasses and generative C++.

Herb Sutter's talk about it is by far the best talk I've seen from from CppCon17. — HN, 2017

Programming language design · C, C++, Rust, Go & systems languages

Subtitles (excerpt)

- Thank you, Don. (audience applauding) Just before we get started, thank you very much to over 70 people who responded to this challenge before the Monday night cutoff. That made it very hard to pick winners. I could only pick two, so first of all, many of you gave very nice solutions, thank you. And since I had to pick two, let me describe very briefly the exercise and then show you the two who have some wonderful iPads that I'm told run great Google search and Microsoft Office as well. (audience laughing) The idea is I want to write a case-insensitive string class. It's a strawman example. There are other ways you could do it. But if I wanted this kind of type, how many comparison operators would I have to write today in C++17, the latest modern stuff we just shipped, in order to provide comparisons between CIString and CIString, CIString char* C-cell strings. And of course, that has to be symmetric. And even the CIString, CIString, I would like to be symmetric because you want conversions on both sides. The answer is, yeah, 12 ought to do it. No wait, 18 ought to do it. And how many of you have enjoyed writing code like this? Sorry, how many of you have written code like this? Way more hands. Only a couple of enjoyers.

On Hacker News

The talk about the reflection proposal was amazing. Meta classes are also very cool. We can only hope it comes fast. [VIDEO] — xaedes, 2018-01
Herb Sutter's talk about it is by far the best talk I've seen from from CppCon17. "Meta: Thoughts on generative C++" - [VIDEO] — slavik81, 2017-10
A few years ago Herb Sutter proposed Python-like metaclasses in C++ through compile-time code generation. Not sure if anything has been proposed for general use. [VIDEO] — tylerhou, 2020-12
To a degree, but templates and constexpr don't support a bunch of features like compile-time field enumeration and introspection + code generation. For example, let's say I have a bunch of structs: struct GeoCoordinate { int lat, long; }; struct GeoArea { std::vector<GeoCoordinate> perimeter; }; struct Place { std::string name; std::string contact_number; GeoArea area; }; Now I need to serialize … — tylerhou, 2020-12

Related videos