Back to Basics: Function and Class Templates - Dan Saks - CppCon 2019

Sdílet
Vložit
  • čas přidán 14. 10. 2019
  • CppCon.org
    -
    Discussion & Comments: / cpp
    -
    Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2019
    -
    Generic programming is a collection of techniques for implementing software components that you can adapt easily for a variety of uses. In C++, templates are the primary tool for generic programming, and they're used throughout the standard library. Templates can be functions or classes, as well as variables or type aliases.
    This session is for C++ programmers who would like to shore up their understanding of templates. It describes many C++ template features and offers insights into how compilers use compile-time information, such as types and values, to process templates.
    This session begins by showing how to define function templates and how call them using explicitly-specified or deduced template arguments. It then covers class templates, including the behavior of static data members, friends, and nested classes appearing in class templates. It explains why template definitions require explicit qualification or the keyword typename in some situations. It presents the different forms of template parameters and corresponding arguments, as well as default arguments. Throughout, it clears up common misunderstandings regarding templates, such as the differences among the mechanisms of instantiation and the different flavors of specialization.
    -
    Dan Saks
    Saks & Associates
    President
    Dan Saks is the president of Saks & Associates, which offers training and consulting in C and C++ and their use in developing embedded systems. Dan used to write the “Programming Pointers” column for embedded.com online. He has also written columns for numerous print publications including The C/C++ Users Journal, The C++ Report, Software Development, and Embedded Systems Design. With Thomas Plum, he wrote C++ Programming Guidelines, which won a 1992 Computer Language Magazine Productivity Award. Dan has taught C and C++ to thousands of programmers around the world. He has presented at conferences such as Software Development, Embedded Systems, and C++ World. He has served on the advisory boards of the Embedded Systems and Software Development conferences. Dan served as secretary of the ANSI and ISO C++ Standards committees and as a member of the ANSI C Standards committee. More recently, he contributed to the CERT Secure C Coding Standard and the CERT Secure C++ Coding Standard.
    -
    Videos Filmed & Edited by Bash Films: www.BashFilms.com *-----*
    Register Now For CppCon 2022: cppcon.org/registration/
    *-----*

Komentáře • 50

  • @MarcusAseth
    @MarcusAseth Před 4 lety +68

    He is an excellent teacher, each slide is explained concisely and clearly and he gives you time for the point to sink

  • @middleverse3838
    @middleverse3838 Před 4 lety +19

    We need a Dan Saks for everything.

  • @user-qy6di9li4w
    @user-qy6di9li4w Před 2 lety +8

    47:31 It is a simple fact about why we need "typename". His way of explanation is very enlightening. I wish I could see it earlier.

  • @keithrobinson2016
    @keithrobinson2016 Před rokem +10

    Excellent presenter. Clearly has a deep understanding of the subject and conveys the knowledge really well. Shall look out for more of his presentations.

  • @parth87x
    @parth87x Před 2 lety +5

    This presentation from Dan Saks, is the best intro to Templates. Thanks a lot.

    • @CppCon
      @CppCon  Před 2 lety +1

      Glad you like it!

  • @powkung45
    @powkung45 Před 9 měsíci

    Watching c++ videos makes me appreciate how well TCL in particular uses brackets so nicely, there's no confusion about which relates to what, without overlapping meaning...

  • @hpandeymail
    @hpandeymail Před 3 lety +15

    Just few minutes and I am so much confident that he is a proficient teacher .. thanks for sharing your wisdom 🙏

    • @CppCon
      @CppCon  Před 3 lety +2

      Glad to hear that

  • @yasamanderiszadeh902
    @yasamanderiszadeh902 Před rokem +1

    Fantastic talk! Was able to not only teach one topic very clearly, but also touch on other topics of C++ programming without confusing and distracting the audience.

    • @CppCon
      @CppCon  Před rokem

      Thank you so much for your comment!

  • @nicolasjochem1814
    @nicolasjochem1814 Před 4 lety +8

    i love it, one is really rewarded for concentrated listening here because he grasps it so well in "each sentence"

  • @chrisshyi8999
    @chrisshyi8999 Před 4 lety +12

    Excellent presentation on templates, I learned a lot!

  • @yashtrikannad518
    @yashtrikannad518 Před 4 lety +9

    One of the best talks I've heard on templates! Very concisely explained

  • @kamilziemian995
    @kamilziemian995 Před rokem

    Back to Basics is the best learning material for C++ that I found on the CZcams.

    • @CppCon
      @CppCon  Před rokem +1

      Thank you for letting us know that you find the Back to Basics track very educational.

  • @gregwoolley
    @gregwoolley Před 3 lety +9

    Nice talk, well explained, thank you. Thank you also CppCon for providing these great videos, much appreciated!

  • @ian3084
    @ian3084 Před 4 lety +2

    These lectures are invaluable. Nice presentation.

  • @kulakulagundi
    @kulakulagundi Před 3 lety +4

    Excellent, I am his fan since 2001 when I started reading his articles in ESP magazine.

  • @user-zp3nd6ht8v
    @user-zp3nd6ht8v Před 4 lety +2

    Very good tutorial, I can see his passion for it. Thanks, bro!

  • @anthonyrocha8075
    @anthonyrocha8075 Před 4 lety +1

    Very clear explanation of a tricky feature.

  • @jvsnyc
    @jvsnyc Před 3 lety +6

    This is really good. There are a lot of talks and blogs, etc. etc. about templates which would be great if you have already watched this one and learned everything in it, but are terrible icy lakes to jump into from scratch.

  • @ordinaryguyx
    @ordinaryguyx Před 2 měsíci

    Excellent teacher and clear explanation thanks!

  • @perfumedsea
    @perfumedsea Před 4 lety +3

    Very good presentation on template basics. I liked how typename is introduced part and the specialization materials. I found most tutorials will skip these basics.

  • @MikeMitterer
    @MikeMitterer Před 3 lety +4

    Boy, what a great presentation!

    • @CppCon
      @CppCon  Před 3 lety +1

      Glad you liked it!

  • @sizur
    @sizur Před 4 lety +2

    This presenter is superb!

  • @pawanadhikari110
    @pawanadhikari110 Před 4 lety +1

    Clear and concise

  • @nukemate
    @nukemate Před 3 lety +2

    It's really good explanation. Covered all basic aspects! Thanks!

    • @CppCon
      @CppCon  Před 3 lety

      Glad it was helpful!

  • @PerisMartin
    @PerisMartin Před 4 lety +1

    If I ever meet Mr Saks on the street I'll give him a hug

  • @vincezzz9757
    @vincezzz9757 Před 2 lety +2

    clear and concise. thank you!

  • @vhlk
    @vhlk Před rokem

    Awesome video!!!!

    • @CppCon
      @CppCon  Před rokem +1

      Glad you enjoyed it

  • @Poti221
    @Poti221 Před 3 lety +4

    Amazing!

  • @ZackDia-Ptr
    @ZackDia-Ptr Před rokem

    After two presentations for this Prof, i am starting to see oop more clearly... thanks!

  • @carlschumann
    @carlschumann Před rokem

    1:01:15 terminology specialization and instantiation

  • @IdanBanani
    @IdanBanani Před 3 lety

    great!

  • @lck5217
    @lck5217 Před 4 lety +1

    56:58
    Functions have external linkage by default, I think we can do the same with explicit specialization declaration like this:
    main.cpp
    // ****************
    #include "f.hpp"
    template void f();
    int main()
    {
    f();
    return 0;
    }
    // ****************
    f.cpp
    // ****************
    #include "f.hpp"
    template void f()
    {
    cout

  • @shrivatsankchari1729
    @shrivatsankchari1729 Před 2 lety

    58:19 wouldn't that throw an error? Early on in the presentation he said return types are not deduced and need to be specialized at declaration.

  • @rafalmichalski4893
    @rafalmichalski4893 Před 4 lety +1

    Would it compile from slide 85 ? npos is typically size_t constant with max or -1 (e.g. for std::string) so we are trying to init pointer to size_t (typename T::size_type *) with size_t constant(T::npos) here I guess. But I might be wrong of course.

  • @johnshaw6702
    @johnshaw6702 Před 3 lety +1

    It could use improvement, but not bad. I did learn a couple things about modern C++, that I did not know about.
    The piece towards the end about comparing those character array pointers was not correct though. The stack starts at a high address and each subsequent item pushed on it has a lower address. So the address of array starting with 'N' is actually higher. As a concept explanation it my not seem important, but in the real world it can be very important.

    • @jamesburgess9101
      @jamesburgess9101 Před 2 lety +2

      Fun fact: standard C++ (and C) deliberately say absolutely nothing about the direction of the stack. It can be either and some architectures, like ARM, it is selectable. If you think knowing the direction of the stack is important (which it is) you will also definitely want to know this: the compiler in standard C++ (and C) is at liberty to rearrange your variables on the stack! The order you write them in your source code is not the order it has to allocate them.
      We should forget the stack though, that example did not specifiy if the pointers where even on the stack and that certainly was not the point of the example.

  • @wenhailong6192
    @wenhailong6192 Před rokem

    where the slide

  • @antonfernando8409
    @antonfernando8409 Před 2 lety

    Nice and simple, now I understand template, just that him checking his time so often is kind of odd lol.