Better C++ Ranges - Arno Schödl - [CppNow 2021]

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ม.ค. 2025

ความคิดเห็น • 4

  • @SamWhitlock
    @SamWhitlock 3 ปีที่แล้ว

    16:37 I think the idiomatic way to silence this error is to specialize the `enabled_borrowed_range` template en.cppreference.com/w/cpp/ranges/borrowed_range

  • @raymundhofmann7661
    @raymundhofmann7661 3 ปีที่แล้ว

    What about this solution for the dangling problem at 25:58?
    auto fun()
    {
    using namespace ranges::view;
    // a vector by value
    auto v = std::vector{1,2,3};
    auto w = filter([](auto i){ return i%2;});
    // return a lambda which captures the vector
    // and provides this and the filtered vector when called
    // to avoid a dangling reference
    return [=]{ return std::make_tuple(v, v | w);};
    }
    Unfortunately the use of this as a whole is limited, as when using it you have to take care that the lambda stays alive so its captures stay alive.
    Here C++ gets nasty, i hope compilers will give more help/warnings/errors about various object lifetime troubles in the future.

  • @shashwatganesh5415
    @shashwatganesh5415 3 ปีที่แล้ว

    This seems very similar to Rust's iterators, but in C++. Very cool.

    • @broken_abi6973
      @broken_abi6973 3 ปีที่แล้ว +1

      Rust iterators look like other language iterators as well