CppCon 2017: Herb Sutter “Meta: Thoughts on generative C++”
CppCon2 HN recommenders · recommended in 2 months, 2017–2020
talk · advanced · 2017–2020 on HN
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.
Praised as the best talk of CppCon 2017 and the key introduction to metaclasses and generative C++.
Up next
3 mo on HNWild Tricks for Greenscreen in Blender
IanHubert
3 HN recommender · 2020–2026
3 mo on HNBlender Motion Tracking - Room Transformation!
IanHubert
4 HN recommender · 2020–2022
5 mo on HNBut what is the Riemann zeta function? Visualizing analytic continuation
3Blue1Brown
6 HN recommender · 2017–2023
6 mo on HNCppCon 2015: Greg Law " Give me 15 minutes & I'll change your view of GDB"
CppCon
6 HN recommender · 2018–2023
4 mo on HNCppCon 2017: Louis Brandy “Curiously Recurring C++ Bugs at Facebook”
CppCon
4 HN recommender · 2020–2025
7 mo on HNCppCon 2014: Chandler Carruth "Efficiency with Algorithms, Performance with Data Structures"
CppCon
7 HN recommender · 2014–2024
3 mo on HNHow wildlife trade is linked to coronavirus
Vox
5 HN recommender · 2020–2020
11 mo on HNCppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
7 HN recommender · 2017–2025
12 mo on HNLexical Scanning in Go - Rob Pike
GoogleFOSSSydney
13 HN recommender · 2012–2025
10 mo on HNCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
9 HN recommender · 2018–2026
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
10 mo on HNCppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”
CppCon
13 HN recommender · 2016–2024
4 comments from Hacker News
The talk about the reflection proposal was amazing. Meta classes are also very cool. We can only hope it comes fast. ▶ this video
Herb Sutter's talk about it is by far the best talk I've seen from from CppCon17. "Meta: Thoughts on generative C++" - ▶ this video
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. ▶ this video
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 these structs into a format to be sent over the wire. Currently, I have a few choices: 1. Use an off-the-shelf library like protobuf (disclaimer: I work for Google). Then I have to convert my code to a protobuf definition and rely on its code generator to perform [de]serialization. I also have to hope that my library supports all the field definitions I need. 2. Write macros to define each field in each structure. These macros perform some arcane magicks that somehow create the necessary [de]serialization functions. These macros are difficult to write and maintain (or I find a library). 3. Manually define the methods myself. This is tedious, hard to maintain, and error prone. What if I could write some code in C++ which could read the structure and generate the appropriate serialization code? Something like (syntax hypothetical): Serializable(Class) { std::string serialize() { std::string output; for (auto member : Class.members()) { // loop unrolled at compile time if (member.type == int) { output.append(std::format("{:10}"), member.get()) } else if (member.type == std::string) { ...