Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just today I saw a (2 year old) video on that very topic in Rust and C++: https://www.youtube.com/watch?v=algDLvbl1YY Towards the end they mention what to use instead in C++ to get the same characteristics as Rust's Vec::reserve:

    vec.insert(
        vec.cend(),
        std::move_iterator(newElems.begin()),
        std::move_iterator(newElems.end())
    );


This is roughly analogous to Vec's specialised Extend implementation. Like that feature it only helps if you've got a similar API shape you're adapting. If we need to make newElems then we're probably not getting a perf win from this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: