Template Metaprogramming: Type Traits (part 2 of 2) - Jody Hagins - CppCon 2020

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ย. 2020
  • cppcon.org/
    github.com/CppCon/CppCon2020/...
    Watch Part 1: • Template Metaprogrammi...
    ---
    PART 2/2 - This talk experienced some latency issues, but the slides and audio are mostly unaffected.
    Template metaprogramming is a vast subject, but there are a small number of basic fundamental idioms that are used over and over. Mastery of these idioms will help in reading, writing, and using modern C++ code. The type traits that come as part of the standard library are incredibly useful, but at times can be thought of as some form of dark magic.
    In this tutorial, we will explore some of the fundamental idioms of template metaprogramming by implementing a good portion of the type traits from the standard library. In so doing, attendees will come away with a solid understanding of how to apply the fundamental template metaprogramming idioms to solve problems including, but not limited to, standard type traits.
    ---
    Jody Hagins first compiled "C++" code in 1984, and wrote a specialized LisP editor using Zortech C++ for senior project in 1988. However, he didn't truly start programming in C++ until 1992, when he read The Greatest C++ Book Ever Written, "Advanced C++ Programming Styles and Idioms" by Jim Coplien. That book, combined with cfront, which generated C code from C++ source, gave him the joyful task of writing SVr4 Streams drivers in C++. Ever since, he has been hooked on writing C++ code for kernel modules, large telephony applications, and, since the late 1990s, applications in what is now known as the high frequency trading industry.
    ---
    Streamed & Edited by Digital Medium Ltd - events.digital-medium.co.uk
    events@digital-medium.co.uk
    *-----*
    Register Now For CppCon 2022: cppcon.org/registration/
    *-----*
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 25

  • @hectorgalbissanchis3831
    @hectorgalbissanchis3831 3 ปีที่แล้ว +17

    This two videos about type_traits have been awesome. I needed a video like these two. Nice job!

  • @coder2k
    @coder2k 3 ปีที่แล้ว +7

    This talk makes me realize once again what geniuses the developers of C++ compilers must be. Great talk (both parts) btw, thank you!

  • @filipkrolupper
    @filipkrolupper 3 ปีที่แล้ว +3

    I graduated 2001 and from that time I haven't updated my C++ knowledge. My head is going to explode, thanks! :-)

  • @edubmf
    @edubmf 2 ปีที่แล้ว +3

    Thank you Jody for taking the time to create both these presentations. Massively useful and very well done.

  • @SamWhitlock
    @SamWhitlock ปีที่แล้ว +1

    51:43 I always kinda knew what SFINAE was, but after this explanation, I finally get it! Fantastic presentation!

  • @bobbymah2682
    @bobbymah2682 2 ปีที่แล้ว +1

    This is one of the best presentations on template meta programming.

  • @d_bud
    @d_bud ปีที่แล้ว

    Thanks! A really nice refresher since I'm looking for a job in c++ again, after quite a few years.

  • @whitenigga2929
    @whitenigga2929 2 ปีที่แล้ว +1

    Good tutorial, Mr. Jody.
    I watched both parts and I'm glad I came across your tutorial.
    Finally understood what partial/full specialization and tag dispatch are all about. And I understood decltype/std::declval usage.

    • @CppCon
      @CppCon  2 ปีที่แล้ว +2

      Glad it helped!

  • @lexshardaduriz1036
    @lexshardaduriz1036 3 ปีที่แล้ว +2

    I loved the way that has explained `decltype` remarkable :D

  • @kalesantosh
    @kalesantosh 3 ปีที่แล้ว +2

    Great talks!

  • @tsunekakou1275
    @tsunekakou1275 3 ปีที่แล้ว +1

    it took me a while to learn metafunction conventions, template parameters matching, sfinae this video will be very helpful to those starting in template meta programming. I hope you will upload the presentation, i couldn't find it in cppcon's github. i really want to see that recursive metafunction slides.

  • @d_bud
    @d_bud ปีที่แล้ว

    "thank goodness to vim macros" killed me

  • @oisyn
    @oisyn 3 ปีที่แล้ว +1

    @Simon Farre who asked in the chat for an is_in_pack definition: you could do something like this: godbolt.org/z/7afE68

  • @phonlolol5153
    @phonlolol5153 3 ปีที่แล้ว +6

    great talk with a good structure. but i think the sfinae slides are somewhat wrong.
    see this godbolt link:
    godbolt.org/z/YT1E75
    1. the static assert on slide 82 is wrong. can_have_member_ptr is not "callable" with nullptr. it is the resolved type coming from the decltype expression, which will be true_type or false_type. so the nullptr is wrong in the "call". additionally the decltype in the static_assert will give us the type and not the value. we dont need the decltype at all because this is already done in the aliasing template definition.
    2. substitution != deduction. template argument deduction is just to determine the type. you may pass just an int (and skip deduction) and use can_have_pointer_to_member directly. the int will get substituted and will fail for the member pointer case. it works. (see godbolt). you just need to get the decltype and value instantiation right.

    • @meowawful
      @meowawful 3 ปีที่แล้ว +2

      Am I getting it right that with the
      static_assert(not can_have_member_ptr{});
      we return std::true_type/std::false_type, then construct an object of that type and convert implicitly with constexpr operator value_type()? wouldn't it be easier to just do
      static_assert(not can_have_member_ptr::value);

  • @d_bud
    @d_bud ปีที่แล้ว

    How would you implement `is_pack_of`?

  • @yiwang1111
    @yiwang1111 2 ปีที่แล้ว

    Is it a typo @53:01 in the first is_class_or_union function. Should it return std::is_union::value?(aka the not is a bug). Did I miss anything?

    • @paulcarter4631
      @paulcarter4631 ปีที่แล้ว

      I think there is a typo, but just with the names. The function should be called detail::is_class instead of detail::is_class_or_union. is_class is the title of the slide and the name of the final function at the bottom of the slide. The detail struct matches both classes and unions, so the _not_ is there to have is_class return false for a union.

  • @jhbonarius
    @jhbonarius 3 ปีที่แล้ว +5

    Very interesting... but it's like somebody took me to the hardware store and showed me all the tools they sell there. Well, that's very nice. But I still have no idea how to use them.

    • @rastaarmando7058
      @rastaarmando7058 3 ปีที่แล้ว

      that's more your problem than his tho.

    • @__hannibaal__
      @__hannibaal__ ปีที่แล้ว

      Imagine you make natural_number class that need only accept only integer time.
      Make function that add two number and you have to make choice for bigger size type…., there more usefull …

  • @clydexu2599
    @clydexu2599 2 ปีที่แล้ว

    42:00 decltype

  • @OGdoCavaco
    @OGdoCavaco 2 หลายเดือนก่อน

    “This is template metaprogramming” no fooling around

  • @rudyardkipling4517
    @rudyardkipling4517 3 ปีที่แล้ว +2

    nice to see someone using std::string std::(whatever?) I can't stand it when people using namespace std