C++ Weekly - Ep 449 - More constexpr Math!

Поділитися
Вставка
  • Опубліковано 25 гру 2024
  • ☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟
    Episode details: 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
    Amazon Paperback: amzn.to/47MEAhj
    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...

КОМЕНТАРІ •

  • @adityapratapsingh2518
    @adityapratapsingh2518 2 місяці тому +36

    Hey jason, can you please do a series on concurrency and multithreading in c++? And what resources will you recommend to someone getting started with it?

    • @sinom
      @sinom 2 місяці тому +1

      If you just specifically want info on how to apply these concepts in C++ just look up thread/jthread, future and promise on cppreference
      (Or just the entire "concurrency" section on cppreference in general)

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

      I'm always happy to get topic requests - I track them here: github.com/lefticus/cpp_weekly/issues/ You can add your request and vote on the others.

  • @RomanOrekhov
    @RomanOrekhov 2 місяці тому +14

    4:06 since when is log10 considered a trigonometric function?

    • @kangaroo1689
      @kangaroo1689 2 місяці тому +3

      Also, since when is acosh the arccosine hypotenuse and not the hyperbolic arccos?

    • @realwermos
      @realwermos 2 місяці тому +2

      It's a little sad as this is a video worth making but his lack of knowledge of basic mathematical things hinders the watch experience. A little research would have gone a long way. "Hey, I'm not sure what acosh stands for, let me look it up just to be sure."

  • @AJMansfield1
    @AJMansfield1 2 місяці тому +6

    Regarding "building data tables at compile time", I'd be interested in a look at how best to workaround the lack of constexpr malloc or new. When I wrote my library for generating sparse matrix structures at compile time (CSR and COO), I was able to get something _like_ memory allocation, by manually managing an arena -- but it was *very* awkward, needing a whole separate parallel implementation of the logic just to calculate the arena's size first, before using the real algorithm to populate it.

    • @Roibarkan
      @Roibarkan 2 місяці тому +1

      I think this is what Jason (@cppweekly) calls “The constexpr 2-step” which he presents here: ua-cam.com/video/_AefJX66io8/v-deo.html

    • @ZoranRavic
      @ZoranRavic Місяць тому

      If push comes to shove you can always create a separate program to per-calculate the data and save it in a header file of your main app.

  • @LesleyLai
    @LesleyLai 2 місяці тому +5

    The thing that we are all waiting for! Implementing your own constexpr sin/cos/log/pow etc is just obnoxious. Also, the gcem library looks pretty cool

    • @AtomicAndi
      @AtomicAndi 2 місяці тому +1

      apparently it IS hard as compilers are slow to implement it.

  • @3bdo3id
    @3bdo3id 2 місяці тому +2

    2:20
    Came here to search about the constexpr with data tables that Bob Steagall mentioned you "chastised him continuously for not making everything constexpr" in his talk in CppCon 2018 at 01:04:35 on the CppCon YT channel. And guess what, you mentioned it in a video 14 hours ago!!

  • @aidananderson7587
    @aidananderson7587 2 місяці тому +2

    fyi, the trig functions that end in h at 6:39 are hyperbolic functions. It's not arc cosine hypotenuse, instead it's hyperbolic arc cosine. en.wikipedia.org/wiki/Hyperbolic_functions

  • @master138
    @master138 2 місяці тому +2

    That spin tho🔥🔥🔥

  • @austinbachurski7906
    @austinbachurski7906 2 місяці тому +1

    That outro with no music really threw me off for a second.

  • @Raspredval1337
    @Raspredval1337 2 місяці тому +8

    more I dabble with 'pure' constexpr (to use as less template metaprogramming at compile time as possible), more I think it was a mistake. The idea is clearly practical, but the way it's done is just bad. Unless you do some compile time parsing + error checking (like in fmt library) it's easier to just generate a .cpp file with an external tool to fill the data and then use some extern api to access it.

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

      Could you please mention any specific drawbacks of "pure" constexpr apart from language availability? As for reading or "including" data from external sources, there is a proposal for it: preprocessor #embed.

    • @schmide
      @schmide 2 місяці тому +1

      @@aniketbisht2823 I think the onus is to show constexpr's necessity. I only see it used trivial cases and have yet to see it used in any computationally intense code.

    • @aniketbisht2823
      @aniketbisht2823 2 місяці тому +5

      ​@@schmide I personally use constexpr to do all sorts of "wild" stuff in personal projects using the trunk version of compilers. It's always better to do those computations in the language itself rather than employing any external tools, for most cases.
      Nevertheless, adding compile time computation ability in C++ is more about removing restrictions rather than actually "adding" stuff into the language. The keyword "constexpr" was already added in C++11. In C++ runtime and compile time code looks the same modulo certain restrictions. Even the new SIMD proposal is constexpr compatible. Exceptions, atomics and std::format are also being proposed to be made available at compile time.
      You never know when you might require a certain algorithm(s) or function(s) at compile time. Major implementations already use an interpreter for constexpr. It's also UB free and consequently used by many teams for testing purposes. There is a talk on CppCon about testing code used in kernel development using constexpr to check for UBs.
      Conclusion: constexpr doesn't make C++ complicated. It's more about removing restriction regarding what is compile time computable .

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

      @@aniketbisht2823 That's another thing I can't wrap my head around, atomics and constants. There is this M&M mutex and mutable as seen in the shared_mutex example cppreference that absolutely makes no sense. Something is either const or not. If you lock something you are no longer const and are now affecting other non const objects. Bad for the caller who thinks they are receiving a constant but is not. Bad for the callee who gets a call from a space where it assumes it is not affecting runtime but actually is.

    • @sinom
      @sinom 2 місяці тому +2

      ​@@schmidethis really doesn't have anything to do with constexpr
      Usually if you pass something by const reference it's because you only want to read the data, not modify it. In that managed counter example you're talking about, they want readers to be able to use that same interface of passing by const ref.
      The thing that you usually expect to be const when passing around is the data, in the case of that example the mutex is not considered to be part of the data but instead a way of managing access to the data. What you're getting is also a copy of the data, so it is obviously no longer managed. Yeah mutable member variables often aren't the best idea but I don't really see any issue with that example specifically.

  • @z08840
    @z08840 27 днів тому

    logarithmic functions are not trigonometric :)

  • @AtomicAndi
    @AtomicAndi 2 місяці тому +1

    When is it coming to compilers near us?
    That is the question you needed to research ;-)

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

    Cool, I tried to skip all the usual promotion and self promotion, but failed badly ;-)