Cute C++ Tricks, Part 2.5 of N - Code You Should Learn From & Never Write - Daisy Hollman - CppCon22

Sdílet
Vložit
  • čas přidán 28. 05. 2024
  • cppcon.org/
    ---
    Cute C++ Tricks, Part 2.5 of N - More Code You Should Learn From and Never Write - Daisy Hollman - CppCon 2022
    github.com/CppCon/CppCon2022
    During the COVID-19 global pandemic, as we all searched for ways to stay connected to the C++ community, these 25-line or less C++ snippets of counterintuitive C++ code called the "Cute C++ trick of the day" started to appear on Twitter. The amount of attention these tricks got was surprising, and as more were posted, it became clear that these counterintuitive snippets of C++ code offer pithy and memorable ways to teach people some intermediate or advanced aspects of C++ (that often come up in real code!).
    This talk builds on part 1 (of N), presented last year at CppCon 2021. In this presentation, I will dissect a few more of the most popular "Cute C++ tricks" to a level of detail not possible on social media platforms like Twitter. I'll talk about how and why these tricks work the way they do, talk about the dark corners of C++ they touch upon, and talk about what you should actually do if you need to produce the same effect in production code. While not targeted at beginners, these tricks span the gauntlet from features that most intermediate programmers are aware of (but never thought to use in a particular way) to dark corners of the language that many of my C++ committee colleagues were surprised to learn about. Throughout it all runs a common thread: learning how to exploit your own curiosity to expand your toolbox, gain a better grasp of the fundamentals of C++, and ultimately, become a better programmer.
    ---
    Daisy Hollman
    Dr. Daisy S. Hollman began working with the C++ standards committee in 2016, where she has made contributions to a wide range of library and language features, including proposals related to executors, atomics, generic programming, futures, and multidimensional arrays. Since receiving her Ph.D. in Quantum Chemistry in 2013, her research has focussed primarily on parallel and concurrent programming models, though a broader focus on general accessibility of complex abstractions has become her focus in more recent years. She currently works on C++ language and library design at Google, where she continues to focus on providing broad accessibility of programming models and abstractions, with a particular focus on design for diversity and inclusivity.
    ---
    Videos Filmed & Edited by Bash Films: www.BashFilms.com
    CZcams Channel Managed by Digital Medium Ltd events.digital-medium.co.uk
    #cppcon #programming #cpp
  • Věda a technologie

Komentáře • 20

  • @FF_Fanatic
    @FF_Fanatic Před rokem +2

    In my own experience, the one scenario where I've desired to have function template partial specialization was when the template parameter is used only as a template parameter and not as a function parameter. Overloads don't help at all for that, but you can of course work around it via a `wrapper` function parameter where `wrapper` is functionally identical to `std::type_identity`.

  • @embeddor3023
    @embeddor3023 Před rokem +8

    Can we please add the overload set pattern into the standard? It's very useful for variant visitation and it doesn't make any sense to keep writing this manually everytime we need this ...

    • @Roibarkan
      @Roibarkan Před rokem +1

      I believe it's discussed in the committee - p1772 (and p0051).

  • @FF_Fanatic
    @FF_Fanatic Před rokem +1

    The trick to replace a primary template is 100% UB because you can't just put stuff in std willy-nilly, but it's incredible that in practice, you can now bring C++ back to the old JS days of just replacing something you don't like. You can't have constraints on non-template functions (yet? didn't follow whether it was delayed or denied), but that would've gotten us pretty damn close, not that the standard library has much non-template code anyway.

  • @Bolpat
    @Bolpat Před rokem

    44:00 Note that for user-defined char sequence literals, you also get separator and decimal point characters. For that reason, you cannot simply subtract '0' and add.

  • @Bolpat
    @Bolpat Před rokem

    10:20 Actually, there’s four ways to express constrained template parameters because you can put a requires clause behind the template parameter list and behind the function parameter list. The second version exists so you can refer to parameters in the constraints (e.g. decltype(param)), but to be honest, I don’t really understand where requires behind the template parameter list really shine.

  • @Bolpat
    @Bolpat Před rokem

    Hex floating point literals are nuts: static_assert(0xAB.Cp1 == 0x55.Ep2); That is because the exponent is 2-based, not 16-based: static_assert(0xAB.Cp0 == 0xA.BCp4); Can you guess what 0x1.4p3 is?

  • @JohnWasinger
    @JohnWasinger Před rokem

    Nice plug for Python there. 49:30

  • @lukasz2345
    @lukasz2345 Před rokem +1

    Where I can find that slides?

    • @Roibarkan
      @Roibarkan Před rokem +2

      The link is on the bottom left of every slide, ends with cppcon-2022 (sorry for not putting a link, youtube won’t allow it)

  • @Roibarkan
    @Roibarkan Před rokem +1

    19:16 “requires expression”, I believe

  • @6eeykwr2
    @6eeykwr2 Před rokem

    Great talk as always Daisy

  • @PaulMetalhero
    @PaulMetalhero Před rokem

    Why do you write class instead of typename?

    • @eLBehmo
      @eLBehmo Před rokem +1

      Slide code / it's shorter

  • @WndSks
    @WndSks Před rokem +3

    Code font is too small as usual on these talks.

    • @KulaGGin
      @KulaGGin Před rokem +1

      It's just fine on my monitor. -Get a bigger monitor.- Just kidding. The player should allow zooming in and out. Well, if you really want to, PotPlayer allows to open YT videos and easily zoom in and out, and move the focused part to where you want it.

  • @michaelzomsuv3631
    @michaelzomsuv3631 Před rokem +2

    Is there an equivalent of this talk but for C?

    • @AstuteJoe
      @AstuteJoe Před rokem

      Yeaaaaaaaaah, this template stuff also doesn't quite interests me, but something digging deep into pointers, SIMD instructions, memory management, etc... would be awesome! Arena allocators? There's some cool trickery when replacing free and malloc

  • @__hannibaalbarca__
    @__hannibaalbarca__ Před rokem +1

    May be my word will be very harmful; i should tell it:
    These day c++ standard-er need to learn deep concepts of mathematics logics and predicate calculus, topology and algebraic topology;
    The old way of concept is more better than key word concepts and should be replaced by TheCondition ;
    Because Concepts should build a fonction or Templates and under the template we write what the conditions should be for the parameter ; the concepts gave a general rule inside class or function {like return type, errors, max_memory or type of execution ……….} . Am y right.