Some abstracts: Metaprogramming aims to accomplish a little more in Compile time. One of the solutions for C++ is template and its friends (because template is Turing-complete).. The speaker starts with the problem of function template overloading and function template specialization. How to help the compiler determine and choose the suitable template by type becomes the concern of metaprogramming. Taking is_container at compile time as an example, he goes from trait, enable-If_t (C++11) + SFINAE + void_t to concepts (C++20) to solve this problem in different ways. The final conclusion is that concepts and its library are great, and we recommend you use this to check the template type.
Concepts are really amazing. I tried to watch some talks with how metaprogramming worked before concepts and I had to pause a video every 30 seconds. With concepts I didn't even have to pause once. Amazing talk. Thank you so much and to the ones that made concepts possible.
for the question @ 50:00 (I'm not a c++ expert) shouldn't there be NO drawbacks at all on the generated code. isn't only the compilation time affected?
Check out the techniques presented here - I believe it can be used to check whether padding is used in aggregate types. ua-cam.com/video/gF48LDy-6lY/v-deo.html
Found quite several errors in his code examples. Some are just typos; but others are fundamentally wrong. E.g. the concept `BeginAndEndCopyConstructibleAndDestructible` should not be defined with `requires` expression but a merely `&&`s of those constraints. And in `struct is_container` the last a few lines of `&&`s should not be in `integral_constant` but in a `enable_if_t`, because even if some of those constraints are not met, the `integral_constant` and the resulting `void_t` are still well formed.
Some notes: 1. slides are being changed fast 2. It would be nice to explain what you're trying to do first and then explain some code. At least for me it is hard to make connections between slides etc. So, you should consider that not everyone is expert in metaprogramming, especially when you're explaining more or less basic stuff compared to what experts know.
A good talk, but I wish people would stop abusing language putting the "-able" suffix to everything, and instead start using "Has-", "Is-" and "Can-" more. "Beginnable", "Endable", "Incrementable" etc are horrible unnatural names for concepts, they look like a brain cancer from Java. "HasBegin", "HasEnd", "CanIncrement" etc are much closer to the natural language and more conceptual, as we use concepts to test for identity ("is"), posession ("has"), ability ("can") etc.
Incrementable is a real word and is also the word used by the standard i.e. std::incrementable. It is hardly abuse to use real world terms for things, and I disagree with the assertion that a universal style is necessary to accommodate your own aesthetic considerations for use of the English language as long as the style used is consistent in this codebase. You are ignoring the obvious, that "-able" has incredibly clear meaning in this context, i.e. to make a word active rather than passive; i.e. it can be so. It would be absurd if used to show ownership, but that isn't being done. The concept isn't that a function "has begin", it's that the begin act can be done on it; it doesn't matter if it "has" some concept of begin if that begin isn't a method to begin the process of iteration, so querying if the type is beginable makes perfect sense. Has should be used for fields, since that is data possed/owned/referenced by the type, and should never be used in my opinion to query the presence of functionality; functionality is a question of "do-ability" i.e. -able, not ownership.
@@masondeross I think you have a point. using the right word is very opinion based and depends on the particular case. I don't fully agree that even keeping it consistent in the code base is really necessary (it's more about when someone sees it how quickly they can infer what the concept means without looking further). all the can/is/has/-able have there places they are just wasy to communicate intent.
I am not sure about C++, but in Java the -able naming is used because it actually makes more sense from a natural language point of view. I would rather say "The class List is a Beginable" than "The class List is a CanBegin"
Actually it has done it since the beginning of C++, now it's just easier to achieve and actually readable by people that are not super professional in templates.
@@cppnext-alexd I do not know what this says about C++ has a language. Is this a good or bad thing? It is so complex that its compilers have emergent behaviours that were never predicted but discovered.
Well. It's sort of old hat that meta programming was discovered by mistake. Turns out it's Turing complete, or so the canon goes, I believe. Being able to compute things at compile time is not in and of itself a bad thing. You can precalculate look up tables for example.
The slide at 44:30 is great - cause actually Nothing was gained in terms of readability, you only left out the code of "beginAndEndCopyConstructibleanddestructible" (what a horrible mess that is). So after a decade of trying C++ finally gives us somewhat usable error-messages. And i have to somewhat agree: it should not be called meta-programming for C++ - it is nothing like normal programming.
The irony of him saying that he is jumping the shark when he meant jumping the gun, only this is also C++ literally jumping the shark... so it's double funny.
I’m so sorry. I’m less than 10 minutes in, and the mental gymnastics you’re asking me to execute are just preposterous. I’m sure this is a good talk, but I can’t help but think that it’s “lipstick on a pig”. C++ is the best worst language I’ve been forced to use. I just wish it didn’t suck so much.
The examples the speaker uses are very impractical and atypical of the features being shown. They're likely miscellaneous examples to make the point, but the impracticality is distracting for sure But in the end of their talk, the point is that *they agree with you* - they're providing historical context about C++ meta programming to show where it's at now and how much it's improved since the clunky, unmanageable SFINAE soup versions.
If you know how to use every feature of cpp, you can program in almost in any language very fine( only ok in functional programming languages though.) So you should feel lucky to be forced to learn from grandfather of all modern languages.
Some abstracts:
Metaprogramming aims to accomplish a little more in Compile time. One of the solutions for C++ is template and its friends (because template is Turing-complete)..
The speaker starts with the problem of function template overloading and function template specialization. How to help the compiler determine and choose the suitable template by type becomes the concern of metaprogramming.
Taking is_container at compile time as an example, he goes from trait, enable-If_t (C++11) + SFINAE + void_t to concepts (C++20) to solve this problem in different ways.
The final conclusion is that concepts and its library are great, and we recommend you use this to check the template type.
Concepts are really amazing. I tried to watch some talks with how metaprogramming worked before concepts and I had to pause a video every 30 seconds. With concepts I didn't even have to pause once. Amazing talk. Thank you so much and to the ones that made concepts possible.
What a clear explanation! Much easier
for the question @ 50:00 (I'm not a c++ expert) shouldn't there be NO drawbacks at all on the generated code.
isn't only the compilation time affected?
So you were saying that my very wide monitor is now no longer needed when debugging c++ compiler messages?
He is so happy about these new features! I love it :)
Thank you so much, I never used templates/concepts and now looks awesome to check :D
Great presentation! Loved it!
17:44, why f need to be a template? if f are regulary (member) function, would overload resolution still choose the correct member?
Great presentation
Nice presentation, thanks Alex!
Awesome talk
good talk!
Thanks for the video, it’s very interesting and easy to follow
35:08 so the Neqable that’s going to constrain the second argument of foo()will actually be Neqable and not Neqable
true It's important to point that out because in other case (unlike in this case) it would really make a difference
Can we metaprogram a way to check if a struct/class has the optimal order of fields (for smallest size) ?
I don't understand your question. There is no reflection in cpp(yet). So I guess the answer is very likely to be no.
Check out the techniques presented here - I believe it can be used to check whether padding is used in aggregate types. ua-cam.com/video/gF48LDy-6lY/v-deo.html
Found quite several errors in his code examples. Some are just typos; but others are fundamentally wrong.
E.g. the concept `BeginAndEndCopyConstructibleAndDestructible` should not be defined with `requires` expression but a merely `&&`s of those constraints.
And in `struct is_container` the last a few lines of `&&`s should not be in `integral_constant` but in a `enable_if_t`, because even if some of those constraints are not met, the `integral_constant` and the resulting `void_t` are still well formed.
Can someone explain the difference between void_t and enable_if and when to use each?
@44:58
Machine: "It is 83.6% readable"
Me: "..."
The real killer app of concepts is introspective programming.
Some notes:
1. slides are being changed fast
2. It would be nice to explain what you're trying to do first and then explain some code. At least for me it is hard to make connections between slides etc. So, you should consider that not everyone is expert in metaprogramming, especially when you're explaining more or less basic stuff compared to what experts know.
A good talk, but I wish people would stop abusing language putting the "-able" suffix to everything, and instead start using "Has-", "Is-" and "Can-" more. "Beginnable", "Endable", "Incrementable" etc are horrible unnatural names for concepts, they look like a brain cancer from Java. "HasBegin", "HasEnd", "CanIncrement" etc are much closer to the natural language and more conceptual, as we use concepts to test for identity ("is"), posession ("has"), ability ("can") etc.
Incrementable is a real word and is also the word used by the standard i.e. std::incrementable. It is hardly abuse to use real world terms for things, and I disagree with the assertion that a universal style is necessary to accommodate your own aesthetic considerations for use of the English language as long as the style used is consistent in this codebase. You are ignoring the obvious, that "-able" has incredibly clear meaning in this context, i.e. to make a word active rather than passive; i.e. it can be so. It would be absurd if used to show ownership, but that isn't being done. The concept isn't that a function "has begin", it's that the begin act can be done on it; it doesn't matter if it "has" some concept of begin if that begin isn't a method to begin the process of iteration, so querying if the type is beginable makes perfect sense. Has should be used for fields, since that is data possed/owned/referenced by the type, and should never be used in my opinion to query the presence of functionality; functionality is a question of "do-ability" i.e. -able, not ownership.
@@masondeross I think you have a point. using the right word is very opinion based and depends on the particular case.
I don't fully agree that even keeping it consistent in the code base is really necessary (it's more about when someone sees it how quickly they can infer what the concept means without looking further).
all the can/is/has/-able have there places they are just wasy to communicate intent.
I am not sure about C++, but in Java the -able naming is used because it actually makes more sense from a natural language point of view. I would rather say "The class List is a Beginable" than "The class List is a CanBegin"
How about a type traits with says 5 method requirements?
understandable
So C++ compilers can now execute code like an interpreter? All this for generic programming to work? Epic.
Actually it has done it since the beginning of C++, now it's just easier to achieve and actually readable by people that are not super professional in templates.
@@cppnext-alexd I do not know what this says about C++ has a language. Is this a good or bad thing? It is so complex that its compilers have emergent behaviours that were never predicted but discovered.
@@jewulo it's a happy discovery.
But since then it's planned and the progress is wonderful.
Now we need to run metaprograms on GPU or parallell CPU😍
Well. It's sort of old hat that meta programming was discovered by mistake. Turns out it's Turing complete, or so the canon goes, I believe.
Being able to compute things at compile time is not in and of itself a bad thing. You can precalculate look up tables for example.
The slide at 44:30 is great - cause actually Nothing was gained in terms of readability, you only left out the code of "beginAndEndCopyConstructibleanddestructible" (what a horrible mess that is).
So after a decade of trying C++ finally gives us somewhat usable error-messages.
And i have to somewhat agree: it should not be called meta-programming for C++ - it is nothing like normal programming.
The irony of him saying that he is jumping the shark when he meant jumping the gun, only this is also C++ literally jumping the shark... so it's double funny.
I’m so sorry. I’m less than 10 minutes in, and the mental gymnastics you’re asking me to execute are just preposterous.
I’m sure this is a good talk, but I can’t help but think that it’s “lipstick on a pig”.
C++ is the best worst language I’ve been forced to use. I just wish it didn’t suck so much.
The examples the speaker uses are very impractical and atypical of the features being shown. They're likely miscellaneous examples to make the point, but the impracticality is distracting for sure
But in the end of their talk, the point is that *they agree with you* - they're providing historical context about C++ meta programming to show where it's at now and how much it's improved since the clunky, unmanageable SFINAE soup versions.
You do avoid a lot of boilerplate sometimes
@@AirAKose I don't agree with the impractical point.
It really depends on what you do.
All the examples are very practical in my line of work.
He started with the old way of doing it, and then jumps to how the new way is better.
If you know how to use every feature of cpp, you can program in almost in any language very fine( only ok in functional programming languages though.) So you should feel lucky to be forced to learn from grandfather of all modern languages.