Lightning Talk: operator for - C++ Generator Ranges Without Coroutine Overhead - Jonathan Müller

Sdílet
Vložit
  • čas přidán 2. 10. 2023
  • www.cppnow.org​
    / cppnow
    ---
    Lightning Talk: operator for - C++ Generator Ranges Without Coroutine Overhead - Jonathan Müller - CppNow 2023
    Slides: github.com/boostcon/cppnow_pr...
    ---
    If you want to support the range-based for loop for your type, you have to write an iterator for it. Depending on the complexity of the range, this can be really complicated, since you need to awkwardly model a state machine. Luckily, since C++23 we have std::generator, which gives us a way of using coroutines to specify the range - just write a loop and co_yield each value. However, coroutines have significant overhead, may introduce heap allocation, and are in general more difficult for the optimizer to reason about.
    A much simpler solution is to write a function that takes a lambda, which is then invoked for each element. This is fast, but a bit awkward since you cannot use the range-based for loop. This talk discusses `operator for`, an upcoming C++ proposal that adds language support for this pattern.
    ---
    Jonathan Müller
    Jonathan is a library developer at think-cell. In his spare time, he works on various C++ open source libraries for memory allocation, cache-friendly containers, or parsing. He also blogs at foonathan.net and is a member of the C++ standardization committee.
    ---
    Video Sponsors: think-cell and Bloomberg Engineering
    Audience Audio Sponsors: Innoplex and Maryland Research Institute
    ---
    Videos Filmed & Edited By Bash Films: bashfilms.com/
    CZcams Channel Managed & Optimized By Digital Medium Ltd: events.digital-medium.co.uk
    ---
    CppNow 2024
    www.cppnow.org​
    / cppnow
    ---
    #boost #cpp #cppnow
  • Věda a technologie

Komentáře • 4

  • @Voy2378
    @Voy2378 Před 6 měsíci

    at 2:54 I presume [=] capture is terrible for performance?

  • @ashrasmun1
    @ashrasmun1 Před 8 měsíci

    Ok but... why... Seems a bit over the top.

    • @ultradude5410
      @ultradude5410 Před 7 měsíci

      Nicer code without coroutine overhead

    • @guiorgy
      @guiorgy Před 7 měsíci

      Either you have many places in your code that loops over exactly, and exactly, 3 sequences, and you want to simplify the code, or you could make a variasic template with this and make it generic