C++ Weekly - Ep 348 - A Modern C++ Quick Start Tutorial - 90 Topics in 20 Minutes

Поділитися
Вставка
  • Опубліковано 19 гру 2024

КОМЕНТАРІ • 86

  • @darkmagic543
    @darkmagic543 2 роки тому +62

    Some bonus features:
    * exceptions, catch ellipse
    * structured binding
    * forward declaration
    * namespaces
    * rule of 5, default and nontrivial/virtual destructors
    * memory, pointers and smart pointers
    * iterators and writing your own iterator
    * multithreading
    * numeric
    * explicit/implicit conversions
    * casting, slicing
    * variant & visitor
    * abstract class (pure virtual), delete, final
    * consteval
    * packages & libraries, cmake
    * signed/unsigned arithmetic, bitwise operations, bitset

    • @_Omni
      @_Omni 2 роки тому +9

      empty base optimization

    • @volchonokilliR
      @volchonokilliR 2 роки тому

      just a little bonus >w

  • @treyquattro
    @treyquattro 2 роки тому +49

    the way to become a C++ expert: read and entirely internalize the standard. I haven't and that's why, after decades - DECADES! - of C++ use and work I'm still watching these videos!

  • @cppweekly
    @cppweekly  2 роки тому +19

    A couple of small notes:
    * don't start manually ordering all of your lambda captures. This is not behavior that is specified in the standard. I just wanted you to be aware of it.
    * Some of the C++ standards / features got off, my mistake. Example: Explicit template parameters for lambdas are from C++20.
    I'll continue to update this comment for this very dense episode as things are found.

  • @hagenmuller4568
    @hagenmuller4568 2 роки тому +10

    Ever since I started developing in C++ with my first job in 1997, I had the feeling that the more years of experience in C++ I had, the less confident I became, and the more there was that I didn't know. Now, I have an extensive list which I can go through and improve on (or even get to know, for that matter) all the topics I don't feel confident enough in.
    Thanks a lot, Jason! That list is very helpful! And the video's a lot of fun to watch😁

    • @polardevelop
      @polardevelop Рік тому

      I am really glad that you wrote this comment, because I made the same experience. And thanks Jason really helpful, like your videos. 20 minutes are perfect to watch (not to short not to long)

  • @PedroOliveira-sl6nw
    @PedroOliveira-sl6nw 2 роки тому +9

    I am amazed at myself that at 13:00 I actually thought about ordering, size of lambdas JUST before you mentioned it. Feeling proud.

    • @cppweekly
      @cppweekly  2 роки тому +5

      Just be aware that I would put this in the category of hyper optimization if you start going around manually ordering captures. This is not, nor should be, a normal thing to do. And it's also not specified by the standard.

  • @fcolecumberri
    @fcolecumberri 2 роки тому +7

    More than practice, something I have seen to helps a lot to improve at programming with a certain language/framework/technology/etc. is to reads others peoples code.

  • @blaisofotso3439
    @blaisofotso3439 Рік тому +2

    Hallo Jason,
    Great job bringing this to the public. I am pretty new to c++ and wouod appreciate if you make show us which topics to know for beginner and intermediate .

    • @cppweekly
      @cppweekly  Рік тому +4

      I've tried to put together an ordered playlist for "learning" topics ua-cam.com/play/PLs3KjaCtOwSY34fFKyhOFovFlB7LikDwe.html

  • @thestarinthesky_
    @thestarinthesky_ Рік тому +1

    @3:37 Is the absence of an inherent 'this' pointer for lambdas an intentional design to avoid such ambiguities, or is there another rationale behind it? I'm speculating that this design choice might be due to potential ambiguities, especially in scenarios where a lambda might capture the 'this' pointer of an enclosing class. If lambdas inherently had a directly accessible this pointer (like regular objects), and they also captured an enclosing this, it could lead to confusion. Am I right?

    • @cppweekly
      @cppweekly  Рік тому +1

      Very intentional - `this` always refers to the containing object that the lambda was created in.

  • @darckangenoir
    @darckangenoir 2 роки тому +6

    move semantic and forwarding/universal ref

  • @PedroOliveira-sl6nw
    @PedroOliveira-sl6nw 2 роки тому +9

    You left out multithreading and maybe the memory model (?)

    • @johanngerell
      @johanngerell 2 роки тому +1

      Sure, but he didn't say that the covered topics are *all* the things that the "expert level" is comprised of, just that they *are* at the "expert level"

    • @PedroOliveira-sl6nw
      @PedroOliveira-sl6nw 2 роки тому +3

      @@johanngerell sure. He also asked to comment things he might had left out. =D

    • @johanngerell
      @johanngerell 2 роки тому +1

      @@PedroOliveira-sl6nw fair enough :)

  • @milosko1616
    @milosko1616 2 роки тому +15

    Well, after using C++ for a last 6 years, its still a really long path for me to be an expert... :D I fell like i know nothing now..:X

    • @coder2k
      @coder2k 2 роки тому

      I guess that will never change....feel you :D

  • @ilciavo
    @ilciavo 2 роки тому +4

    90 shots of C++ Espresso

  • @TheSulross
    @TheSulross 2 роки тому +6

    a booklet could be fashioned around this presentation and it would make a nice companion quick reference - kudos for this nifty angle of attack

    • @cppweekly
      @cppweekly  2 роки тому +1

      You might check out this one: leanpub.com/cpplambda I have not read it, but it should have a fair bit of overlap.

    • @TheSulross
      @TheSulross 2 роки тому +1

      @@cppweekly What did you think of Herb Stutter's presentation on his cpp2 proposal?
      It seems like he has more actual pragmatic headway on his ideas than does the Google Carbon project (and seems like, to me, Herb is taking a superior approach in respect to migration from and compatibility with the C++ parent language)
      Would be great to hear your observations in a video

  • @Omnifarious0
    @Omnifarious0 2 роки тому +1

    7:00 - I think 'efficiency when chaining functions' belongs somewhere near here and not earlier where you put it. When the parameters were int and int &, there was, very technically, a copy issue, I suppose. But no compiler would've cared.
    But, as soon as you made it a template with a T first parameter, there was definitely an issue.

    • @dascool3st
      @dascool3st Рік тому

      I didn't understand 'efficiency when chaining functions' , and googling doesn't seem to help (maybe I'm not searching the right terms). Where could I learn about this from?

    • @corpseopera
      @corpseopera Рік тому

      @@dascool3st did you find some info about it yet?

  • @tonygreenberg7441
    @tonygreenberg7441 2 роки тому +3

    Friend functions?

  • @MegaCashB
    @MegaCashB 2 роки тому +2

    How are you typing both in the void lambda() and the struct Lambda() at the same time? what sorcery is this @ 4:21?

    • @ajinkyakamat7053
      @ajinkyakamat7053 2 роки тому +7

      That's a C++23 feature know as multiple keystroke elision. The compiler figures out that you are writing the same thing twice and auto populates code for you.
      Jokes aside in clion Ctrl+Shift+Click let's you set multiple cursors for typing the same thing. It's available in VSCode too.

  • @johnhsu5459
    @johnhsu5459 2 роки тому +1

    Hi, really want to know what is the
    template overload(Ts...) -> overload
    means and does. It does no sense to me and I never see anything similar in my life ever, don't even know how to Google it..

    • @xorbe2
      @xorbe2 2 роки тому +1

      You want to look up "C++ deduction guide" which guides from ctor to template params.

  • @userrand4900
    @userrand4900 Рік тому

    Do you need to duplicate the static method inside the lambda, CPP insights seems to delegate to the member function implementation from the static method via a temporary (which should be fine since these are captureless lambdas) ? Also presumably with inlining the overhead of delegating should be zero (at least at higher optimization levels) ?

    • @cppweekly
      @cppweekly  Рік тому

      CppInsights is not technically correct here, it's impossible to get the same guarantees as the standard requires using delegating code like they are. In general it's actually impossible to directly model what the compiler does for Lambdas using user defined code.

    • @userrand4900
      @userrand4900 Рік тому

      @@cppweekly thanks. What are the guarantees that might be violated with delegation?

  • @Faris-1900
    @Faris-1900 Рік тому

    Last time I used C++ seriously was almost 10 years ago. How to grasp all those new concepts? Any advice of a good reference?

    • @cppweekly
      @cppweekly  Рік тому +3

      I tend to recommend "A Tour of C++" which is linked in the video description.

  • @Chris-yw5is
    @Chris-yw5is 2 роки тому +4

    exceptions should be easy to add to the list as well

  • @CharlesHogg
    @CharlesHogg 2 роки тому +1

    As for "your favorite C++ feature"---did I miss it, or were designated initializers left out? Not that it's my _absolute_ favorite, but it's super useful for improving code health.

    • @cppweekly
      @cppweekly  2 роки тому

      I did miss designated initializers, you're right

  • @danielrhouck
    @danielrhouck 2 роки тому +1

    My favorite feature you didn’t cover, which can apply to lambdas in various ways: concepts and constraints.

    • @cppweekly
      @cppweekly  2 роки тому +1

      I touch on it at 8:42 briefly.

    • @danielrhouck
      @danielrhouck 2 роки тому

      @@cppweekly Oops, you did, I missed that.

  • @von_nobody
    @von_nobody 2 роки тому +1

    Template meta programing, this means in simple terms code that take one type and return other type that have specific relation to first one, e.g. "preferred container for type X", and you by default return `std::vector` but for other it would be `std::list` or better `std::deque`.
    And this is only tip of iceberg.

    • @cactus-man
      @cactus-man 2 роки тому

      And?

    • @cppweekly
      @cppweekly  2 роки тому +1

      I have a weird relationship. I have used (and do use) it extensively when I need to. But in my mind it is kind of a technique to use when there isn't a better option.
      I find fewer and fewer uses for it as constexpr becomes more powerful.
      But you are correct, I didn't really mention that in the episode.

    • @von_nobody
      @von_nobody 2 роки тому

      @@cppweekly yup, most fun experiment I make was creating Stack Turing Machine purely using template metaprograming :D

  • @jobinthomas6372
    @jobinthomas6372 Рік тому

    How are you typing so fast ? What keyboard are you using ?

  • @i_am_acai
    @i_am_acai 2 роки тому

    Could you explain 3:32?

    • @cppweekly
      @cppweekly  2 роки тому +1

      Once you know how a lambda works you expect that `this` should refer to the lambda object itself, but it does not. It can only refer to a captured `this` pointer. There is no way to model this with equivalent code. It's "magic"

    • @userrand4900
      @userrand4900 Рік тому

      ​@@cppweekly There is still a "this" pointer except that it can't be referred to using this. IOW, the first argument to the lambda (if it has one) is passed into %esi vs. %edi.

  • @auric88
    @auric88 Рік тому

    explicit lambda templates were added in C++20, not in C++17

  • @michelchaghoury9629
    @michelchaghoury9629 Рік тому

    I Am new to C++ this channel is amazing but were do i start?

    • @cppweekly
      @cppweekly  Рік тому

      somewhere around episode 5 I think :D

  • @dimitrilesnoff468
    @dimitrilesnoff468 6 місяців тому +1

    I did not find the video topics list nor in the description, nor in the comment section:
    * lambdas
    * struct
    * constexpr
    * operator overloading
    * call operator
    * const member functions
    * braced initialization
    * `auto` return type deduction
    * "compiler magic"
    * function parameters
    * pass-by-value
    * attributes on parameters
    * pass-by-reference
    * pass-by-value vs pass-by-reference
    * pre-increment vs post-increment
    * trailing return types
    * class vs struct
    * private vs public
    * implicit conversions
    * function pointers
    * static member functions
    * using aliases
    * efficiency when chaining functions
    * templates
    * template argument type deduction
    * alias templates
    * template instantiations
    * `noexcept`
    * `noexcept` in the type system
    * variadic templates
    * variadic lambdas
    * fold expressions
    * function attributes
    * concepts
    * non-type template parameters
    * integer sequences
    * template parameter pattern matching
    * explicit lambda templates
    * tuples
    * unpacking of tuples
    * variadic `sizeof...()` operator
    * direct-initialization of members
    * `mutable` keyword
    * non-`const` member functions
    * reference members
    * member copies
    * object layout
    * member padding
    * order of construction / destruction
    * generalized lambda capture
    * immediately invoked lambdas
    * return value optimization
    * guaranteed return value optimization
    * initializer_list
    * recursive lambdas
    * deducing `this`
    * recursive functions
    * trivially copyable types
    * higher order functions
    * dangling references
    * undefined behavior
    * inheritance
    * multiple inheritance
    * function hiding
    * variadic `using` declarations
    * scoping / lookup rules
    * class template argument deduction
    * deduction guides
    * algorithms
    * ranges
    * ``
    * virtual member functions
    * member function pointers
    * special member functions
    * member function call syntax
    * type erasure
    * dynamic vs automatic storage
    Missing
    * writing own concepts
    * type_traits
    * operator
    * protected
    * virtual inheritance
    * compilation model
    * ODR violations
    * preprocessor
    * project structure and layout
    * the breadth of the standard library
    * variable templates
    * coroutines
    * modules

  • @rolandinnamorato1953
    @rolandinnamorato1953 Рік тому +2

    Alternative title: Why C++ is Insanity

  • @kimhyunpil
    @kimhyunpil 2 роки тому

    unbelievably great

  • @tonybalinski2398
    @tonybalinski2398 2 роки тому +2

    Great checklist and presentation. Covers almost everything In the language except modules and coroutines. Curiously, there is no array manipulation or memory allocation, and pointers are (happily) thin on the ground.
    Others have mentioned other lacunae but, after them, we’re into esotericism like atomics and laundry.

  • @TheMR-777
    @TheMR-777 2 роки тому +6

    Man! That felt fantastic, and it was quite motivational. :)
    Title can be, 20 mins of Self-confidence in C++
    Well, I have a little thought too, about std::tuple{};
    10:17 - Why std::apply isn't used here? I believe, it would simplify the code, + would make it much, much readable.

    • @cppweekly
      @cppweekly  2 роки тому +2

      I actually didn't think of std::apply, but did in a future episode that is coming up soon. I need to probably do an episode about that.

  • @CharlesHogg
    @CharlesHogg 2 роки тому +1

    2:11 "There are some exceptions, of course, and I am going to list those..."
    I watched the whole video, and I didn't see exceptions mentioned. 😉

    • @cppweekly
      @cppweekly  2 роки тому

      They are the 12 listed at the very end, which lambdas do not directly go into.

    • @CharlesHogg
      @CharlesHogg 2 роки тому

      @@cppweekly Sorry, I was trying to make a terrible pun about "exceptions, the C++ feature". Of course, I could easily have missed that you _did_ talk about them, and then the joke's on me!

  • @numv2
    @numv2 2 роки тому

    Brilliant !

  • @S1lentSt0rm
    @S1lentSt0rm Рік тому

    15:46 what the actual?

  • @tetsuoshiva
    @tetsuoshiva 2 роки тому

    My days of applying for an interview where they will ask questions about syntax are over. Kek.

  • @drygordspellweaver8761
    @drygordspellweaver8761 Рік тому +1

    This comes across as satire. Poe’s law in action

  • @krofikS4
    @krofikS4 2 роки тому +2

    Polymorphic clone function, just to add one.

    • @cppweekly
      @cppweekly  2 роки тому +2

      That's kind of covered at the end where I say "make your own std::function implementation" (or whatever)

  •  2 роки тому +1

    Yay, back in the day we were only risked to shoot our foot, now we have to watch out for our faces as well. 🤠

  • @paulcg7566
    @paulcg7566 2 роки тому +2

    Most basic cpp dev: "Cpp is easy"
    Cpp: "yeah son, now try to create a generic lamda"

    • @treyquattro
      @treyquattro 2 роки тому +1

      Has anyone ever said that? My approach has always been: if you understand C++ then you understand computers (knowing machine architecture, instruction set and assembler are prerequisites IMHO too). C++ is life-long learning, which is great for educators like, er, Jason.

    • @volchonokilliR
      @volchonokilliR 2 роки тому

      @@treyquattro I think that before learning C++, it could be taught much better if firstly general concepts of how compilation actually is done in real world, and how CPUs work are taught. So many things started to get their understandable place after learning a bit about these concepts...

  • @biggysmith
    @biggysmith 2 роки тому

    good stuff

  • @ratman-gimmecheez
    @ratman-gimmecheez Рік тому

    THREADS!

  • @cavesalamander6308
    @cavesalamander6308 2 роки тому

    Hmm, I'm still on C++99 ... And I so happy with this.

  • @motbus3
    @motbus3 2 місяці тому

    Not sure if useful as an idea for a video or even if it happens to other people. I can understand modern c+- but i cant write because older stuff seems easier to me.
    Ps. I am c++ dumb but i people still pay me to develop software on other languages, so i suppose i am not the most terrible programmer

  • @muhammadharris4470
    @muhammadharris4470 2 роки тому

    🤯

  • @Fareoneo
    @Fareoneo 2 роки тому

    god he speak so slow

    • @cppweekly
      @cppweekly  2 роки тому +2

      UA-cam has playback speed control