Beyond struct: Meta-programming a struct Replacement in C++20 - John Bandela - CppCon 2021

  Рет қаралды 18,504

CppCon

CppCon

2 жыл бұрын

cppcon.org/
github.com/CppCon/CppCon2021
---
The humble struct. We all use it. We all bump up against its limitations, especially when trying to manipulate it at compile time.
What if I told you that C++20 has enough features that we can meta-program a struct replacement?
Want to have static, compile-time introspection?
Want to add and remove members with compile-time programming?
Want to have type deduction for members?
Want to easily convert from array of structures to structure of arrays (SOA) to optimize cache-friendly traversal?
C++20 allows us to do all these things and more!
No preprocessors, no macros, just standard C++.
Come join me as we explore the magic unleashed by C++20!
---
John Bandela
I first started programming in C++ at age 14 in 1994 when I cajoled my parents into buying me Visual C++ 1.0 for my birthday. It took a while, but as I learned the language, I decided I really liked C++. I attended the University of Florida and obtained my undergraduate degree in Computer and Information Science. During my undergraduate time, I created and submitted Boost.Tokenizer. I went on to medical school and neurosurgery residency, but decided to do something with a little less scary undefined behavior and returned to programming in C++.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
KZbin Channel Managed by Digital Medium Ltd events.digital-medium.co.uk
*--*

Пікірлер: 20
@MaitreBart
@MaitreBart 2 жыл бұрын
It's very interesting on paper (i.e. in a code review). It's full of good ideas. Such code is relatively easy to use and to review. But I'm a pragmatic developer. And in the debugger, that's a whole other story. If the meta_struct is composed of 2 iterators to a deque and 1 bool, and a function returns such an object, finding the value of the bool member in gdb is challenging.
@JohnDlugosz
@JohnDlugosz 2 жыл бұрын
You know, the variable layout of the fields in a structure, as well as automatic AOS to SOA was a fundamental feature of the JOVIAL language. That was in 1958, making it, along with ALGOL itself, one of the first block-structured languages. This particular feature did not catch on and as far as I know was not part of any other major language on the ALGOL family tree.
@N....
@N.... 2 жыл бұрын
34:00 That is actually really cool, I guess since the caller does the matching it's as efficient at runtime as having three reference parameters right? EDIT: Actually I think this can be done with minimal compile overhead and regular structs if person_ref has a template constructor
@petermuller608
@petermuller608 2 жыл бұрын
Great talk! However, the pointer highlighting is highly distracting due to low frame rate
@Ken-S
@Ken-S 2 жыл бұрын
This talk showed a need for dynamic declaration for a type. I think cpp have to consider support "compiler time struct / class" and a way to convert them to "type / template".
@YariRu
@YariRu 2 жыл бұрын
this is crazy
@Solarbonite
@Solarbonite 2 жыл бұрын
It'd be kinda nice to add operator[] for get. I think it should be doable and could make it look more standard? Eg person.id vs person["id"]? Kinda like how lua tables allow . indexing and array indexing.
@VivekNa
@VivekNa 2 жыл бұрын
The field name is a template param. So you can't get that array syntax
@kamlot0
@kamlot0 2 жыл бұрын
I think it is impossible. For get to work you need to know the value of the string at compile time, therefore it has to be inside . person["id"] is equivalent to get("id", person). But it needs to be get(person).
@budiardjo6610
@budiardjo6610 4 ай бұрын
i'm cry
@ratgr
@ratgr 2 жыл бұрын
He asked himself if he could do it never if he should, hahah, amazing metaprograming skill however I woudn't use it, because of compiletime
@combatcorgiofficial
@combatcorgiofficial 2 жыл бұрын
Okay... but like... why? Every time I watch a metaprogramming talk like this I’m immediately reminded of the classic Chandler Carruth “there are no zero cost abstractions” talk. Like, the speaker actually USES this abomination? The amount of time and effort put into just wrapping one’s head around this, much less implementing it, goes so far beyond the reasonable that you’re better off spending a week writing a Python-based C++ code generator with pre-existing JSON/SQL parser libraries and running that at build time. Lord knows it’s probably just as performant.
@alexb5594
@alexb5594 2 жыл бұрын
I would hope a code generator would be just as performant.... As he states in his presentation, twice mind you, this isn't something that one should be doing in their code base as of now. If everyone had an attitude like you do here we would still be using macros (need I say more?), and code generators (out of language, thus no in language error support) for everything. While Carruth's talk was good, I think he was full of **** on parts of it. My opinion of it aside, through time some of his direct criticisms have been patched up, namely compile time due to SFINAE. There is a lot wrong with C++ templates and template meta programming, and it shouldn't be as hard as it is to wrap your head around the arcane parts of it. That doesn't mean that learning it at a deep level is a bad thing, and it takes a deep level of understanding to put something like this together.
@saeed6296
@saeed6296 2 жыл бұрын
I wish there is an explanation for this complicated and ugly syntax 😭
@dozerthecat
@dozerthecat 2 жыл бұрын
C++ gets more academic every update. It's sad. We use c++ for the performance. Stop trying to draw analogies to json parsing. You are killing the language.
@TheIgoorR
@TheIgoorR 2 жыл бұрын
If you know C++ good, you can boost your code performance! This is true reason
@nickwilson3499
@nickwilson3499 2 жыл бұрын
@@TheIgoorR All of c++'s features, yet it's still slower than plain C
@broken_abi6973
@broken_abi6973 2 жыл бұрын
@@nickwilson3499 no, it is not.
Faster, Easier, Simpler Vectors - David Stone - CppCon 2021
1:00:56
1 класс vs 11 класс (неаккуратность)
01:00
БЕРТ
Рет қаралды 4,4 МЛН
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 70 МЛН
microservice communication in node.js
30:34
Code with Jay
Рет қаралды 222
Branchless Programming in C++ - Fedor Pikus - CppCon 2021
1:03:57
Как я сделал домашний кинотеатр
0:41
RICARDO
Рет қаралды 1,5 МЛН
XL-Power Best For Audio Call 📞 Mobile 📱
0:42
Tech Official
Рет қаралды 772 М.
Выложил СВОЙ АЙФОН НА АВИТО #shorts
0:42
Дмитрий Левандовский
Рет қаралды 1,2 МЛН
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 22 МЛН