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

  Рет қаралды 41,992

CppCon

CppCon

Күн бұрын

Пікірлер: 51
@i.8530
@i.8530 2 жыл бұрын
this talk has singlehandedly tought me more than all metaprogramming guides i have read till now. this is truly a fantastic beginner friendly overview.
@__hannibaalbarca__
@__hannibaalbarca__ Жыл бұрын
Before 9 month and after 4 months of c++ learning__self learning__ i understood only 20 % , after 9 months, Im proud of finally u derstand 120% of talk, very good feeling.
@MrIosonoleggenda
@MrIosonoleggenda 10 жыл бұрын
Thank you Walter E. Brown...I could see the happiness in your eyes when you were talking. The best talk in the CppCon.
@oisyn
@oisyn 4 жыл бұрын
Absolute great talk by Dr. Brown! However, I don't really like his answer to the question asked at 43:20. He says "more specialized". Although true, it's important to keep in mind that default template arguments are only part of the declaration, and have nothing to do with the main unspecialized definition that just happens to be in the same line of code. It only started to make sense to me after realizing this. The main definition still defines the generic type, and you can specialize for the case where the arguments are in fact the default arguments further on in a separate specialization. Here's what I mean: template struct foo { ... }; // #1 template struct foo { ... }; // #2 The generic class template foo is defined in #1. It mentions a default argument of void, but that has nothing to to with the actual definition of the generic case! The specialization for when it actually *is* void is provided in #2. Perhaps it helps to read it like this: template struct foo; // just declaration, provides the defaults template struct foo { ... }; // #1 template struct foo { ... }; // #2 This way the disconnect between the default arguments and the main definition and its specializations are more clear. So, in the case of has_member_function, there is another implicit argument that's being used in the 'call', which defaults to void, so it's actually has_member_function. Furthermore, it just so happens to have a specialization for if that void_t thing happens to be well-formed. Otherwise, the whole specialization doesn't exist due to SFINAE.
@KangoAbhiram
@KangoAbhiram 2 жыл бұрын
It is an amazing presentation. Thank you Walter E. Brown and CppCon for such a great content on metaprogramming.
@childhood1888
@childhood1888 2 жыл бұрын
Such a genius! I loved every minute of your talk Dr. Brown.
@echosystemd
@echosystemd 6 жыл бұрын
This old man makes me love template metaprogrammig.
@bobweiram6321
@bobweiram6321 10 ай бұрын
In Part I, Dr. Brown prefaced his talk as covering advanced topics not intended for beginners. He underestimates, however, his ability to distill a complex topic in a clear and intuitive way. I've watched several videos and tried to read a few books and articles on this topic, but they were difficult to grasp. Their explanations quickly glossed over the odd notation, and their chosen examples were obfuscated by other C++ areas. I only planned on watching for a few minutes, expecting to be intimidated and demoralized, but found myself fully engrossed with a clear understanding of the topic.
@StackedCrooked
@StackedCrooked 9 жыл бұрын
This is one of my favorite talks of CppCon along with Jon Kalb's talk on exceptions.
@iam_Raavanan
@iam_Raavanan Жыл бұрын
I learned a lot, and I'm still trying to process it. mostly it takes month to settle down with clarity of what I learned here.
@redchards
@redchards 9 жыл бұрын
I must admit when I first saw it in a stackoverflow thread (can't quite remember which), I was shocked. It's a huge improvement compared to what we had before, this ugly "no evaluation" trick. Nice talk !
@dustinclark5620
@dustinclark5620 Жыл бұрын
Awesome talk
@LamboPhil
@LamboPhil 9 жыл бұрын
I'm gonna call it emvoiden for the time being. Been some time since I last saw something of this degree of awesomeness done to C++, but I wonder if there'll ever be an end to the discoveries in the field of spectacular abuse of Bjarne's accidental meta-child.
@innovationscode9909
@innovationscode9909 2 жыл бұрын
Impressive. Thank you
@CppCon
@CppCon 2 жыл бұрын
Thank you too!
@Bolpat
@Bolpat 2 жыл бұрын
23:10 I wonder if the is_copy_assignable follows the convention. If its _type_ member is aliased to true_type or false_type, wouldn’t one need to write is_copy_assignable::type::value to evaluate it? Wouldn’t you rather define a constexpr bool member _value_ with _decltype( try_assignment(declval()) )::value_ as its definition ?
@grisumbras
@grisumbras 9 жыл бұрын
Last week I saw a trick to create stateful constexpr functions and through this stateful template metaprogramming. Now that was something *really* unexpected. So much unexpected that Standards Committee is considering rewording parts of the standard that allow this for C++17.
@eepp
@eepp 7 жыл бұрын
Link?
@elliott8175
@elliott8175 5 жыл бұрын
Yes, I would love to see that link also, if you could!! (I know that the comment was 4 years ago, but hopefully you still remember the idea!
@mykhailomykytyn
@mykhailomykytyn 3 жыл бұрын
these 2 hr(+) were spent profoundly
@foxtacles
@foxtacles 10 жыл бұрын
void_t for president! fucking awesome
@fangjunkuang5061
@fangjunkuang5061 3 жыл бұрын
eye opening
@ElizaberthUndEugen
@ElizaberthUndEugen 7 жыл бұрын
So why does void_t and class = void have to match?
@J1337H4X0R
@J1337H4X0R 7 жыл бұрын
Because when you call the metafunction, you get [V = void] as the default, and so to get the specialization to activate on that template parameter (the other being a generic type T that can't be specialized), you have to have the same type (V) for that template argument, which means the e.g. void_t, has to be an alias for V, in this case void. void_t is just a weird way of writing void that also does SFINAE on its (unused) template parameters. Without the standardization fix mentioned in the video, the unused parameters might be ignored such that they don't activate SFINAE and so you need the more complex definition of void_t.
@michaelkohlhaas4427
@michaelkohlhaas4427 5 жыл бұрын
@@J1337H4X0R Wrong!
@krzysztofkosinski6664
@krzysztofkosinski6664 4 жыл бұрын
Because you invoke the template as has_type_member. If they didn't match, has_type_member would not consider the specialization at all, because the second type parameter would never match.
@oisyn
@oisyn 4 жыл бұрын
I added a top-level comment that might answer your question.
@moderncpp
@moderncpp 2 жыл бұрын
32:00 I loved it when he laughed at that piece of code
@SanjeevkumarMSnj
@SanjeevkumarMSnj 2 жыл бұрын
template struct is_copy_assignable { private: template static std::true_type try_assignment(U&&); static std::false_type try_assignment(...); public: using type = decltype(try_assignment(std::declval())); }; This version of copy assignable doesn't seem to work with std::string or any type that I've defined with the assignment operator. Any idea why?
@terrortinus
@terrortinus Жыл бұрын
Legend
@anirbansarkar8518
@anirbansarkar8518 6 жыл бұрын
This is genius! Mind... Blown!
@neijiagongfu
@neijiagongfu 10 жыл бұрын
It's not working in MSVC2013 because of the missing expression SFINAE, as Stephan Lavavej mentioned at 25'. Otherwise I would have started my own little concepts lite right now. Damn.
@Slicc12345
@Slicc12345 9 жыл бұрын
correct. but because of reference collapsing it doesn't make a difference cause T&& && will be T&&
@mykhailomykytyn
@mykhailomykytyn 3 жыл бұрын
48:50 You rock!
@ozancansel
@ozancansel 4 жыл бұрын
Thanks for the very good and explanatory talk. Here is the simplified version of is_one_of thanks to fold expressions. template< typename T , typename... T0toTN > struct is_one_of : std::conditional_t< ( std::is_same_v< T , T0toTN > || ... ) , std::true_type , std::false_type > {}; // More simplified template struct is_one_of : std::bool_constant< ( std::is_same_v< Head , Remaining > && ... ) > {};
@Bolpat
@Bolpat 2 жыл бұрын
The last one should better not be named Head and Remaining. They do not form a list conceptually. template struct is_one_of : std::bool_constant {};
@lgsunnyvale
@lgsunnyvale 4 жыл бұрын
Awesome!
@MaceUA
@MaceUA 9 жыл бұрын
Great talk! void_t is an awesome trick. Still, I don't understand one thing. See 50:45, changing is_copy_assignable to is_move_assignable: why "T const&" is changed to "T&&" but not to "T"? declval(T) is already returning an rvalue of type T, isn't it?
@TheLeontheking
@TheLeontheking 2 жыл бұрын
For other people coming here I'll answer this. It's because the return type of `declval` is an rvalue reference, and we're acting like we're passing a value of that type into the `try_assignment`.
@michal.gawron
@michal.gawron 10 жыл бұрын
Wouldn't it be better to name void_t as ensure_well_formed_t?
@Slicc12345
@Slicc12345 9 жыл бұрын
korrect. but because of reference collapsing it doesn't make a difference couase T&& && will be T&&
@mykhailomykytyn
@mykhailomykytyn 3 жыл бұрын
I kinda follow
@saurabhtiwari8174
@saurabhtiwari8174 3 жыл бұрын
Can't has_member_type be implemented as below template struct has_member_type : false_type{}; template struct has_member_type : true_type{}; without the use of void_t at all. I checked it with cout
@vcernobai
@vcernobai Жыл бұрын
Your code is only working when typename T::type is void, in which case the compiler can invoke the partial specialization of the has_member_type template, otherwise it will default to the general case. Try this with the following struct and you'll see its not working: struct Dummy { using type = int; };
@tk-jf6wc
@tk-jf6wc 6 жыл бұрын
wizard!
@childhood1888
@childhood1888 2 жыл бұрын
26:53
@__hannibaal__
@__hannibaal__ Жыл бұрын
First time i see this; is look for me like alien languages.
@childhood1888
@childhood1888 2 жыл бұрын
10:47
@michal.gawron
@michal.gawron 10 жыл бұрын
Or I just found a better candidate: when_valid_t!
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 2,2 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 250 МЛН
C++ Weekly - Ep 342 - C++20's Ranges: A Quick Start
10:13
C++ Weekly With Jason Turner
Рет қаралды 18 М.
CppCon 2014: Scott Meyers "Type Deduction and Why You Care"
1:09:34
Modern Dictionaries by Raymond Hettinger
1:07:41
SF Python
Рет қаралды 143 М.
CppCon 2016: Jason Turner “Practical Performance Practices"
1:00:29
A Medley of C++ - Walter E Brown - C++ on Sea 2022
1:32:21
cpponsea
Рет қаралды 1,9 М.