CppCon 2014: Walter E. Brown "Modern Template Metaprogramming: A Compendium, Part I"

  Рет қаралды 82,363

CppCon

9 жыл бұрын

www.cppcon.org
-
Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2014
--
Template metaprogramming has become an important part of a C++ programmer's toolkit. This talk will demonstrate state-of-the-art metaprogramming techniques, applying each to obtain representative implementations of selected standard library facilities.
Along the way, we will look at void_t, a recently-proposed, extremely simple new new type_traits candidate whose use has been described by one expert as "highly advanced (and elegant), and surprising even to experienced template metaprogrammers."
--
With broad experience in industry, academia, consulting, and research, Dr. Walter E. Brown has been a C++ programmer for over thirty years, joining the C++ standards effort in 2000. Among numerous other contributions, he is responsible for introducing such now-standard C++ library features as cbegin/cend and common_type as well as headers random and ratio , and has significantly impacted such core language features as alias templates, contextual conversions, and variable templates. He conceived and served as project editor for the International Standard on Special Mathematical Functions in C++.
When not playing with his grandchildren, Dr. Brown is an Emeritus participant in the C++ standards process, with several more core and library proposals under consideration. He was recently appointed an associate project editor for the C++ standard itself.
--
Videos Filmed & Edited by Bash Films: www.BashFilms.com
*-----*
Register Now For CppCon 2022: cppcon.org/registration/
*-----*

Пікірлер: 66
@akurmustafa_
@akurmustafa_ 3 жыл бұрын
This is the best presentation, I have seen on cppcon. It is very obvious that the speaker put a lot of effort for preparing this presentation. Timing, design of content, slides, examples chosen just excellent.
@daggawagga
@daggawagga 8 жыл бұрын
It is simply mind-boggling, the way his guy makes this really weird subject become understandable.
@sonulohani
@sonulohani 5 жыл бұрын
Yeah...
@SasLuca
@SasLuca 6 жыл бұрын
"Mathematics is after all just a small branch of Computer Science". That is now my favorite quote of all time.
@vivekpraseed918
@vivekpraseed918 6 жыл бұрын
Luca Sas so spot on
@sonulohani
@sonulohani 5 жыл бұрын
actually its big
@oskarjung6738
@oskarjung6738 Жыл бұрын
"Computer Science is after all just a small branch of Mathematics". There, I corrected you.
@AdrianoDelVigna
@AdrianoDelVigna 3 жыл бұрын
Loved the Borland Turbo C++ color scheme.
@matteobarnaba6518
@matteobarnaba6518 2 жыл бұрын
Words cannot describe how useful, interesting and enlightening this talk is. As someone in the audience said at the end of the second part, you really really rock sir Brown 😊 Thank you and congrats
@CppCon
@CppCon 2 жыл бұрын
Glad it was helpful!
@TheMR-777
@TheMR-777 Жыл бұрын
Producing such a collection of slides requires a tremendous amount of effort and knowledge, similar to writing a research paper. I admire Mr. Brown's work.
@eepp
@eepp 6 жыл бұрын
great speaker! pauses at the right places and all, not hyperactive. clean slides, to the point. subject is so interesting and very well introduced when you're not a TMP wiz.
@smarthumanism3221
@smarthumanism3221 8 ай бұрын
This is a magnificent lecture. Thank you Walter E. Brown for the execellent presentation and teaching!
@moderncpp
@moderncpp Жыл бұрын
Template metaprogramming is fun. Well only after I watched Mr Walter talks.
@TheMR-777
@TheMR-777 Жыл бұрын
That was truly mind-blowing. (while listening to the talk, I am coming to a conclusion, that...) Despite knowing everything about C++, I didn't know anything.
@iam_Raavanan
@iam_Raavanan Жыл бұрын
This is an amazing introduction for Template Metaprogramming. It's too late I reached here, but still worth the knowledge.
@DimitrisAndreou
@DimitrisAndreou 5 жыл бұрын
Amazing job, Walter. The last CppCon talk I watched was from the STL guy. I think his slides were smart but I can't really tell because I couldn't follow. But I grasped everything here. Very intuitive and crisp presentation. Thank you so much
@felipecardoso3142
@felipecardoso3142 3 ай бұрын
That was indeed a great talk!
@magritte128
@magritte128 9 жыл бұрын
This is a great, great talk.
@elliott8175
@elliott8175 4 жыл бұрын
Quick summary: templates were originally meant for use. eg: template struct Blah {...}; // The template seems pointless if you don't use it However, with SFINAE we can use our templates to perform checks: template struct Blah {...}; // Now we make sure that T is default constructible. // This can still make sense even if we don't use S (FYI, because of this, we don't have to give S a name): template struct Blah {...}; So Dr. Brown suggests that its better to throw all of these expressions (where we only care about their validity, and not their evaluated type) into one place (a kind of "black hole"), void_t: template using void_t = void; // He had to implement it in a slightly // more awkward way for clang So if you call it: void_t; Then it checks the validity of the expressions: if all are valid, it returns void, if not, it's SFINAE-ed out. The fact that it has a single and predictable return type is key to its usefulness. As I understand it, that's the purpose of the presentation: to introduce this little tool and show that it's useful. FYI it's now part of the standard library with his suggested name. ************** Now, if someone could help me *********** What is the aim of the code on slides 34/35 (in part II)? His wording here seems super confusing. Is he looking for: 1. Whether T has a member named "type" (where, confusingly, we don't care about its type) 1. --> this option seems the most obvious, except that his code won't compile because of the line 'typename T::type', because 'type' doesn't name a type. 2. Whether T has a member of a certain 'type', but we don't care about its name. 2. --> Again, this won't compile at the same line (expected identifier before 'type') 3. Whether T has an inner type (eg. class/struct/enum declared within it)? 3. --> this compiles and performs the check correctly, but has nothing to do with members of T, so doesn't make sense to me in the context of his presentation. Did he mean to write: struct has_type_member< T,void_t< decltype( T::member ) > > : true_type { }; instead of: struct has_type_member< T,void_t< typename T::member > > : true_type { }; ? This would make 1. work....
@allen-simpson
@allen-simpson 8 жыл бұрын
This is just mind-blowing.
@ultradude5410
@ultradude5410 2 жыл бұрын
Absolutely stellar talk as usual from Dr. Brown! Is there another recording out there with better audio quality? It got pretty crispy in some parts.
@avilachmish
@avilachmish 8 жыл бұрын
wow, great talk!
@mykhailomykytyn
@mykhailomykytyn 2 жыл бұрын
Dr Brown performs like G. This is mind expanding stuff !!!
@zhaoli2984
@zhaoli2984 2 жыл бұрын
Great talk, thank you
@shahmiBro1
@shahmiBro1 5 жыл бұрын
Awesome talk;
@MissNorington
@MissNorington 7 жыл бұрын
I'm impressed....... Very!
@cholocatelabs
@cholocatelabs 7 жыл бұрын
Awesome!!!
@gast128
@gast128 7 жыл бұрын
Clear explanations though many aspects are probably familiar for someone who has survived the Boost.Mpl documentation. I think it's also an improvement to drop the required comment in static_assert, although the use cases shown in the video could have benefit from some extra explanatory text. The modern aspects are handled in part 2.
@colin398
@colin398 Жыл бұрын
I finally understand what SFINAE actually means now thank you
@TheMR-777
@TheMR-777 Жыл бұрын
40:00 I had a couple of questions about it, for a long time. - How the unnamed struct will be declared, if it inherits from another class/struct? - and how the CRTP will be handled in unnamed struct/class?
@ciaranmurraycm
@ciaranmurraycm 6 жыл бұрын
An excellent presentation. I also recommend the following book for meta programming fundamentals : Modern C++ Design : Andrei Alexandrescu
@polskiobywatel553
@polskiobywatel553 3 жыл бұрын
Programs writing programs... Wow!
@Bolpat
@Bolpat Жыл бұрын
53:00 Concepts are in C++20, and it looks like this: template maxint_t f(T val) { … }
@janasandeep
@janasandeep 7 жыл бұрын
Never knew that static_assert statement can be used inside a struct! (16:00)
@themeeman
@themeeman 5 жыл бұрын
It works because static_assert counts as a declaration that doesnt create a name
@Bolpat
@Bolpat Жыл бұрын
14:58 As of C++20, virtual functions can be constexpr.
@VigneshD25
@VigneshD25 2 жыл бұрын
Why can we write something like this instead of specialization ? I got compilation issue but appears valid for me static int constexpr value = (N == 0) ? M : gcd::value; // ignoring M != 0 static assert for this case.
@thisisnotanick
@thisisnotanick 9 жыл бұрын
Great talk, though you could get a better mic for about 10 dollars
@sonulohani
@sonulohani Жыл бұрын
I dont see any issue with the sound
@azadalishah2966
@azadalishah2966 3 жыл бұрын
Slide 14, 1u + rank::value, how is it iterating to next array say from int[10][20][30] to int[20][30] then to int[30]?
@Ulchie
@Ulchie 3 жыл бұрын
This took me a couple minutes to work out, so I figured I'd write it out here. template // non-array (also base case to exit recursion) struct rank { static const size_t value = 0u; } template struct rank { static const size_t value = 1u + rank::value; } Lets say you pass in int[10][20] First iteration, U == int[10], N == 20, expanded with U in parens: struct rank { static const size_t value = 1u + rank:: value; } Second iteration, U == int, N == 10, expanded with U in parens: struct rank { static const size_t value = 1u + rank::value; } Note that rank matches the 0 value base-case, so you end up getting (all expanded inline): struct rank { static const size_t value = 1u + 1u + 0; } The mechanism to erase dimensions is just how the typename U always has to have one fewer dimension than the full type in the struct part since the struct is U[N], so when you pass in int[10][20], U has to be int[10] in order for U[N] to match anything (and in this case, N == 20). Each time you call/recurse into the metafunction, you're calling it with the current U, and the same dimension "erasing" (there's probably a technical name for this...) occurs each time. I hope this makes sense and isn't too poorly worded. In terms of " from int[10][20][30] to int[20][30] then to int[30]?" -- well it goes in the opposite direction. You go from int[10][20][30] to int[10][20] to int[10] to int.
@lakshyarajsinghrathore1902
@lakshyarajsinghrathore1902 2 жыл бұрын
this was the thing I was confused with thanks for asking and thanks @Ulchie for explaining.
@dkosmari
@dkosmari 9 жыл бұрын
He wrote a template to generate newer charts, but it's still compiling. But when it's done, it's sooo gonna be so fast.
@dhikshithrm
@dhikshithrm 2 жыл бұрын
what is the difference between first version and second version of compile time evaluated pow functions v1 and v2 why is there such a big difference in performance
@ejovo
@ejovo Жыл бұрын
We have a big hint given the time complexity of the algorithms. V1 ran in linear time and we deduce that it is simply using repeated multiplication. V2 ran in logarithm time thus we deduce that it is using a recursive scheme to compute the powers. x^8, for example, can be computed with 8 multiplications or x^8 = (x^4)(x^4) = (x^2)^4 which amounts to 5 multiplications
@skeleton_craftGaming
@skeleton_craftGaming 6 ай бұрын
Well, if you define computer science and computational science [which ( in the theoretical domain {at least}) it is] then yes all math is necessarily computer science.
@stefanplusplus917
@stefanplusplus917 6 ай бұрын
but not all math is about computation
@zbjet1
@zbjet1 8 жыл бұрын
This talk is totally nuts.
@videofountain
@videofountain Жыл бұрын
Is this the person you mentioned? EMMY NOETHER
@Cleanser23
@Cleanser23 6 жыл бұрын
It drives me insane when the camera is following a presenter when he is discussing a slide and you have NO IDEA what he's referencing
@LOGNuosCPP
@LOGNuosCPP 6 жыл бұрын
META
@mingwandroid
@mingwandroid 8 жыл бұрын
Yet you think it appropriate to comment without either listening to or understanding his point (delete as applicable). That point being that template metaprogramming has been a usable optimisation for nearly 15 years now. Perhaps were you trying to be funny?
@philipjfry4465
@philipjfry4465 7 жыл бұрын
Tom Hanks :P
@origamibulldoser1618
@origamibulldoser1618 9 жыл бұрын
perl...
@Bolpat
@Bolpat Жыл бұрын
32:20 That iterator_traits has no member named _type_ is actually good. It’s akin to a std::tuple not implicitly converting to its index-0 component.
@Bolpat
@Bolpat Жыл бұрын
54:40 std::integral_constant is a joke because it can take any type and value suitable as a template argument. It’s _not_ - as the name suggests - restricted to integral types.
@dennydaydreamer
@dennydaydreamer Жыл бұрын
Isn't it because that before C++20, template non-type parameters could only be integral, enum or pointer types?
@Bolpat
@Bolpat Жыл бұрын
15:34 The word _weird_ does not mean _unfamiliar._ The former has an objective meaning at least to some degree, but _unfamiliar_ is entirely subjective by definition. You can familiarize with something weird, which in some meaning makes it non-weird to you, but in others, the thing stays weird if it’s generally agreed upon to be weird.
@__hannibaalbarca__
@__hannibaalbarca__ Жыл бұрын
Why KZbin delete my comments when I tell the the truth: C/C++ is best algorithmics and mathematical language. I hope this will stay. First time I don't understand nothing just someone speaking alien language, So I go to Bjarne book for templates and return back here and two times and I start 💡
@childhood1888
@childhood1888 2 жыл бұрын
I hate to type too.
@origamibulldoser1618
@origamibulldoser1618 9 жыл бұрын
underscore T syntax reminds me of perk. yuck.
@FedJimSmith
@FedJimSmith 7 жыл бұрын
Fast forward to 2017... and still concepts lite isn't a standard
@markosx01
@markosx01 8 жыл бұрын
If this is the only thing you took away from this talk, then I suggest you to watch something like "best fails 2015"... What a stupid comment!
@patlecat
@patlecat 9 жыл бұрын
Seriously? You dare to present charts and benchmarks from 2001 in a 2014 talk about "modern" Template Metaprogramming? How lazy can you get?
@ludgergesler3815
@ludgergesler3815 3 жыл бұрын
I think you and the likers of your statement didn't get the key message. It was not about a quantitative comparison, but a qualitative comparison. The absolute numbers may be different on current computers, but the relative comparison remains the same. I know it's hard to understand, but that doesn't make it any less real.
small vs big hoop #tiktok
00:12
Анастасия Тарасова
Рет қаралды 26 МЛН
ROCK PAPER SCISSOR! (55 MLN SUBS!) feat @PANDAGIRLOFFICIAL #shorts
00:31
The joker's house has been invaded by a pseudo-human#joker #shorts
00:39
Untitled Joker
Рет қаралды 15 МЛН