C++ Weekly - Ep 346 - C++23's bind_back

Sdílet
Vložit
  • čas přidán 11. 09. 2024
  • ☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
    Upcoming Workshop: C++ Best Practices, NDC TechTown, Sept 9-10, 2024
    ► ndctechtown.co...
    Upcoming Workshop: Applied constexpr: The Power of Compile-Time Resources, C++ Under The Sea, October 10, 2024
    ► cppunderthesea...
    Episode notes: github.com/lef...
    T-SHIRTS AVAILABLE!
    ► The best C++ T-Shirts anywhere! my-store-d16a2...
    WANT MORE JASON?
    ► My Training Classes: emptycrate.com/...
    ► Follow me on twitter: / lefticus
    SUPPORT THE CHANNEL
    ► Patreon: / lefticus
    ► Github Sponsors: github.com/spo...
    ► Paypal Donation: www.paypal.com...
    GET INVOLVED
    ► Video Idea List: github.com/lef...
    JASON'S BOOKS
    ► C++23 Best Practices
    Leanpub Ebook: leanpub.com/cp...
    ► C++ Best Practices
    Amazon Paperback: amzn.to/3wpAU3Z
    Leanpub Ebook: leanpub.com/cp...
    JASON'S PUZZLE BOOKS
    ► Object Lifetime Puzzlers Book 1
    Amazon Paperback: amzn.to/3g6Ervj
    Leanpub Ebook: leanpub.com/ob...
    ► Object Lifetime Puzzlers Book 2
    Amazon Paperback: amzn.to/3whdUDU
    Leanpub Ebook: leanpub.com/ob...
    ► Object Lifetime Puzzlers Book 3
    Leanpub Ebook: leanpub.com/ob...
    ► Copy and Reference Puzzlers Book 1
    Amazon Paperback: amzn.to/3g7ZVb9
    Leanpub Ebook: leanpub.com/co...
    ► Copy and Reference Puzzlers Book 2
    Amazon Paperback: amzn.to/3X1LOIx
    Leanpub Ebook: leanpub.com/co...
    ► Copy and Reference Puzzlers Book 3
    Leanpub Ebook: leanpub.com/co...
    ► OpCode Puzzlers Book 1
    Amazon Paperback: amzn.to/3KCNJg6
    Leanpub Ebook: leanpub.com/op...
    RECOMMENDED BOOKS
    ► Bjarne Stroustrup's A Tour of C++ (now with C++20/23!): amzn.to/3X4Wypr
    AWESOME PROJECTS
    ► The C++ Starter Project - Gets you started with Best Practices Quickly - github.com/cpp...
    ► C++ Best Practices Forkable Coding Standards - github.com/cpp...
    O'Reilly VIDEOS
    ► Inheritance and Polymorphism in C++ - www.oreilly.co...
    ► Learning C++ Best Practices - www.oreilly.co...

Komentáře • 41

  • @billynugget7102
    @billynugget7102 Před rokem +29

    *Praying the god of c++ makes a coroutines video

    • @kaksisve4012
      @kaksisve4012 Před rokem

      Amen.

    • @kevindelnoye9641
      @kevindelnoye9641 Před rokem +2

      Checkout the cppcon channel, several new talks

    • @destiny_02
      @destiny_02 Před rokem +1

      There was a "Coroutines for Beginners" talk yesterday on cppcon, i feel i understand Coroutines somewhat now.

    • @cppweekly
      @cppweekly  Před rokem +3

      I have a topic request tracker to help me gauge viewer's interest in new topics. Add a thumbs up to the coroutine topic here if you'd like: github.com/lefticus/cpp_weekly/issues/

  • @N....
    @N.... Před rokem +13

    I remember std::bind being discouraged in favor of using lambdas instead, so it's interesting that std::bind_back was added

    • @JFRsAlive
      @JFRsAlive Před rokem +3

      Lambdas are almost always better.
      But if you habe to bind, use bind front or bind back, as they have less foot guns to worry about.

    • @cppweekly
      @cppweekly  Před rokem +1

      Besides footguns, they are much less complex. std::placeholders, while awesome, make bind a complex beast.

  • @mc4ndr3
    @mc4ndr3 Před rokem +4

    In functional programming languages, this capability is known as currying, from the esteemed Haskell Curry. Glad to see it added to the stdlib in C++23!

    • @minirop
      @minirop Před rokem +2

      it's not, bind_front/back do partial function application (it's a tad different).

    • @Nobody1707
      @Nobody1707 Před rokem

      @@minirop Currying is a kind of partial function application. In fact, std::bind_front (with one argument given) _is_ currying.

  • @99curio
    @99curio Před rokem +1

    I think we need a stand alone C++ weekly to go over the bind_back template/lambda code at the end of the session!

  • @JoeDzado
    @JoeDzado Před rokem +2

    Definitely readable.

  • @Tyranisaur
    @Tyranisaur Před rokem +1

    I realize, based on this topic, that using the bind functions seems like a good way to compose calls to functions like any_of, all_of or none_of, when you are working with ranges of simple values, or transformations to simple values. If you want to avoid using lambdas, because lambdas can be verbose.

  • @TheBuilder
    @TheBuilder Před rokem +2

    such a simple feature yet so complicated to implement

    • @cppweekly
      @cppweekly  Před rokem

      That's the simple implementation. I'm sure the actual standard's compliant one would be much worse.

  • @headlibrarian1996
    @headlibrarian1996 Před rokem +3

    That template is a lot more readable than it would have been if implemented using, say, c++14, assuming it could even be implemented in c++14.

    • @Possseidon
      @Possseidon Před rokem +3

      Templated lambdas are a godsend for stuff like this.

  • @friedkeenan
    @friedkeenan Před rokem

    std::bind_back was added by the paper that adds user defined range adaptor stuff. Also I don't think your implementation is standard-compliant, as it doesn't forward on the value category of the binding object to the wrapped function (though this could be solved with deducing this!). Also I don't think returning a lambda would be acceptable in a standard library because if you try to pass around the binding object to functions and such, you could run into issues that you've gone over in one of your recent videos, with conflicting lambda types and such.

  • @jhbonarius
    @jhbonarius Před rokem

    Can't we write a coroutine generator with a ranged view to lazily generate comments for your video?

  • @TinBryn
    @TinBryn Před rokem

    "It's more readable [...], if you're used to reading code like this", what a glowing endorsement.

  • @afaranva
    @afaranva Před rokem

    I'd be really interested in Linux version of this kind of video, or even open source focused

  • @negidrums915
    @negidrums915 Před rokem +1

    I need std::bind_middle

  • @dimon_ksi
    @dimon_ksi Před rokem

    Why to use std::invoke ?

    • @verylongtrain
      @verylongtrain Před rokem +1

      Because it correctly handles function, lambdas, member functions, and even variables (returns their value, as a getter function would), I think. Lots of cases you don't have to handle yourself.

  • @Possseidon
    @Possseidon Před rokem

    While I'm a big fan of functional stuff like this, it really bothers me, that you can rarely make use of them and you have to use a lambda instead, which ends up slightly more verbose (forcing you to name each parameter and such).
    E.g. it breaks when the function has overloads, has default parameters or is templated. And you can never know if a function that works now might change in one of these ways at some point in the future...
    One of the things I really like about Rust btw. They ditched function overloads in favor of making stuff like this work seamlessly. Disallowing overloading might seem limiting at first, but thanks to generics/traits (which, unlike templates, do still work in cases like this) it's actually not a big deal imo.

  • @oschonrock
    @oschonrock Před rokem +2

    Nice. Slight shame your example func took 2 params and you "bound_back" 2 params... which is the same as "bind_front" ?? 😁

    • @Possseidon
      @Possseidon Před rokem +3

      When calling a member function like that, you also have to pass the `this` parameter as a normal parameter, so it is actually necessary ;)

    • @friedkeenan
      @friedkeenan Před rokem +2

      It's not the same as bind_front because bind_front would try to bind the Point object parameter first.

    • @oschonrock
      @oschonrock Před rokem

      @@Possseidon oh yeah... i am sick today... it's showing.

  • @anon_y_mousse
    @anon_y_mousse Před rokem +3

    Personally, I dislike the syntactic mess that C++ has become. But at this point it's too late to be thoughtful with the syntax and make it more readable. Sadly, we have Rustaceans taking over and everything will eventually be Rust so we'll never get good syntax. Oh well, maybe I am right to make my own language since everything else sucks, except for plain ol' C and assembly. All that said, I enjoy these videos because you help me to keep up with the changing standard for C++ and I've incorporated a lot of ideas into my own language that I've gotten from others throughout the years.

    • @dimon_ksi
      @dimon_ksi Před rokem

      Where I can know more about your language?

    • @poulet_malassis7607
      @poulet_malassis7607 Před rokem

      "Everything else sucks, except for plain ol' C and assembly."
      2022 is here, wake up, it's not too late.
      Oh and many programming tasks shouldn't (ever) use C and assembly, or don't need to go that low level. While many others should or could.

  • @MrSandshadow
    @MrSandshadow Před rokem

    we need more '...'!

  • @andreaspokorny3089
    @andreaspokorny3089 Před rokem

    You should have skipped the invoke there - for the sake of readability.

    • @cppweekly
      @cppweekly  Před rokem

      I wanted it to be as complete as possible, while still as simple as possible. It's a tradeoff.

  • @ThatGuy-nv2wo
    @ThatGuy-nv2wo Před rokem +2

    i do not think this is readable, for i am blind

    • @foible2085
      @foible2085 Před rokem

      isn't there a braille encoding for that?

  • @willofirony
    @willofirony Před rokem

    Believe it or not, there are some programmers still say Python is easier to understand than C++. Let this video silence them forever.

  • @cactus-man
    @cactus-man Před rokem +2

    Please do less ketamine, it's impossible to listen to you

    • @cppweekly
      @cppweekly  Před rokem +2

      Feel free to change the playback speed to suit your personal preference!