C++20 Ranges in Practice - Tristan Brindle - CppNorth 2022

Sdílet
Vložit
  • čas přidán 7. 09. 2022
  • CppNorth Twitter: / cppnorth
    CppNorth Website: cppnorth.ca/
    ---
    C++20 Ranges in Practice - Tristan Brindle - CppNorth 2022
    Slides:github.com/CppNorth/CppNorth_...
    CppNorth 2022 video sponsors:
    think-cell: www.think-cell.com/en/
    Adobe: cppatadobe.splashthat.com/
    Among the many new additions to C++20 are Ranges, a modern revision of the STL offering updated algorithms and new “views” with lazy evaluation.
    In this example-based talk we’ll work through several practical demonstrations of how the new Ranges functionality may be used to solve everyday problems concisely, elegantly and efficiently. In addition, we’ll offer tips on how to avoid common errors in your Ranges code, and demonstrate a couple of useful utility functions which you can drop into your codebase today.
    ---
    Tristan Brindle
    Tristan is a freelance developer, trainer and WG21 member based in London, UK. He’s the author of NanoRange, an independent C++17 implementation of the C++20 ranges facilities, and various other open-source tools. He is also a director of C++ London Uni, a not-for-profit organisation offering free weekly C++ classes for students in London and around the world.
    ---
    CZcams Channel Managed By Digital Medium Ltd: events.digital-medium.co.uk
    ---
    #Programming​​ #CppNorth #algorithm
  • Věda a technologie

Komentáře • 10

  • @Roibarkan
    @Roibarkan Před rokem +5

    44:00 the change from call-operator to std::invoke is especially cool for projections, as it allows calling member functions or accessing data members simply by passing pointer-to-member as the projection. Great talk

  • @frydac
    @frydac Před rokem +3

    Have yet to switch to C++20 (gcc format support, pls! and other stuff), this talk was just right for me, easy to follow and learned a lot! Thanks

  • @ChristianBrugger
    @ChristianBrugger Před rokem +2

    A view is a range such that:
    * its move operations are constant-time
    * (if it is copyable) its copy operations are constant time
    * destruction of a moved-from object is constant-time
    * otherwise, destruction is O(N)

  • @ChristianBrugger
    @ChristianBrugger Před rokem +1

    One of the best talk on ranges! Thank you.
    I know it's still very new, and I would love to see some discussion about performance numbers, as well as compile times. What to be careful about.

    • @ChristianBrugger
      @ChristianBrugger Před rokem

      I had wrote one pipeline that took almost 10 seconds to compile and was 2-3 times slower than using algorithms. I am sure there are ways around this.

  • @sirajqazi3287
    @sirajqazi3287 Před rokem

    For the last problem (string trimming), I'd say an even cleaner way to do the trim function would be:
    auto trim() {
    return views::drop_while(::isspace)
    | views::reverse
    | views::drop_while(::isspace)
    | views::reverse;
    }
    handles both front and back trimming. Nice and elegant

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

    the dangling example at 11:00 ish, if ranges didn't do that ASAN would pick it up as a use after free.

  • @peregrin71
    @peregrin71 Před rokem

    Shouldn't template std::string to_string(R& rng), need to constrain to R being a range of a char convertible type too?

  • @dawnadmin8119
    @dawnadmin8119 Před rokem

    Makes me wonder if these first-class functors with composition are going to stay limited to range adaptors. It feels like Alice in Wonderland to have to write a singleton range, like {&x, &x+1}, just to use these abstractions on the base types of the language.
    I know it’s just a demo, but is a string-manupulation function that only works on 8-bit character sets really going to cut it in this century? Maybe there’s a need for a library that stores strings in some sensible form (UTF-8 NFD, stored in a dynamic array of char8_t), ensures that any data stored in it is in properly encoded, and then provides adapters to convert it to other formats. In this case, if there were a member that provided a view of the codepoints as a sequence of wchar_t objects, you could pass that to iswspace() and re-use most of the same logic. (Except on Windows, where wchar_t violates the Standard by not being a fixed-width encoding, so the standard library might break on UTF-16 surrogate pairs.) This lazy conversion through iteration over a range could be much more efficient than eagerly converting the UTF-8 string to a wide string, processing that, and converting back.
    (In a library that needs to remain thread-safe even if some other thread concurrently changes the global locale to one with a different definition of whitespace, you would also need a locale parameter, which could default to the one that was global at the time of the call But that isn’t related to your main topic.)

    • @ChristianBrugger
      @ChristianBrugger Před rokem

      There is a lot of discussion about strings at the moment. See the std::print for example. One problem is that the standard iterator model of 1-by-1 doesn't work anymore and also is inefficient. So they are gona change it starting with replacing std::cout. I am sure more will come, once we have that in place.