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__ Жыл бұрын
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.
@MrIosonoleggenda10 жыл бұрын
Thank you Walter E. Brown...I could see the happiness in your eyes when you were talking. The best talk in the CppCon.
@oisyn4 жыл бұрын
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.
@KangoAbhiram2 жыл бұрын
It is an amazing presentation. Thank you Walter E. Brown and CppCon for such a great content on metaprogramming.
@childhood18882 жыл бұрын
Such a genius! I loved every minute of your talk Dr. Brown.
@echosystemd6 жыл бұрын
This old man makes me love template metaprogrammig.
@bobweiram632110 ай бұрын
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.
@StackedCrooked9 жыл бұрын
This is one of my favorite talks of CppCon along with Jon Kalb's talk on exceptions.
@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.
@redchards9 жыл бұрын
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 Жыл бұрын
Awesome talk
@LamboPhil9 жыл бұрын
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.
@innovationscode99092 жыл бұрын
Impressive. Thank you
@CppCon2 жыл бұрын
Thank you too!
@Bolpat2 жыл бұрын
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 ?
@grisumbras9 жыл бұрын
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.
@eepp7 жыл бұрын
Link?
@elliott81755 жыл бұрын
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!
@mykhailomykytyn3 жыл бұрын
these 2 hr(+) were spent profoundly
@foxtacles10 жыл бұрын
void_t for president! fucking awesome
@fangjunkuang50613 жыл бұрын
eye opening
@ElizaberthUndEugen7 жыл бұрын
So why does void_t and class = void have to match?
@J1337H4X0R7 жыл бұрын
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.
@michaelkohlhaas44275 жыл бұрын
@@J1337H4X0R Wrong!
@krzysztofkosinski66644 жыл бұрын
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.
@oisyn4 жыл бұрын
I added a top-level comment that might answer your question.
@moderncpp2 жыл бұрын
32:00 I loved it when he laughed at that piece of code
@SanjeevkumarMSnj2 жыл бұрын
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 Жыл бұрын
Legend
@anirbansarkar85186 жыл бұрын
This is genius! Mind... Blown!
@neijiagongfu10 жыл бұрын
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.
@Slicc123459 жыл бұрын
correct. but because of reference collapsing it doesn't make a difference cause T&& && will be T&&
@mykhailomykytyn3 жыл бұрын
48:50 You rock!
@ozancansel4 жыл бұрын
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 > && ... ) > {};
@Bolpat2 жыл бұрын
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 {};
@lgsunnyvale4 жыл бұрын
Awesome!
@MaceUA9 жыл бұрын
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?
@TheLeontheking2 жыл бұрын
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.gawron10 жыл бұрын
Wouldn't it be better to name void_t as ensure_well_formed_t?
@Slicc123459 жыл бұрын
korrect. but because of reference collapsing it doesn't make a difference couase T&& && will be T&&
@mykhailomykytyn3 жыл бұрын
I kinda follow
@saurabhtiwari81743 жыл бұрын
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 Жыл бұрын
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-jf6wc6 жыл бұрын
wizard!
@childhood18882 жыл бұрын
26:53
@__hannibaal__ Жыл бұрын
First time i see this; is look for me like alien languages.