Блог*
HashMap<String, Thing> можно индексировать значениями типа &str.
BTW это было в Rust std с самой первой версии, то есть с середины 2015 года. В #cpp подобная вещь называется heterogeneous lookup, и хотя она реализована для контейнеров в std, она opt-in. Для упорядоченных контейнеров нужно явно дописывать
std::less<> в шаблонные параметры типа, а для неупорядоченных вообще надо самостоятельно писать хешер и явно дописывать is_transparent в определении. Вдобавок heterogeneous lookup на упорядоченных контейнерах был с C++14, а вот на неупорядоченных его не было до выхода C++20 — то есть на четыре года позже, чем в Rust.👍7
#prog #cpp #article
On push_back_unchecked: Performance with FromIterator and Collect
TL;DR: в другом посте предлагали добавить в вектор операцию
On push_back_unchecked: Performance with FromIterator and Collect
TL;DR: в другом посте предлагали добавить в вектор операцию
push_back_unchecked, которая не проверяет ёмкость перед записью (и, соответственно, на полном векторе даёт UB). Замеры показали, что это даёт ускорение по сравнению с push_back в цикле. Автор же этой статьи сделал API FromIterator (взятый из std Rust) для своей библиотеки контейнеров и показал, что для таких юзкейсов можно добиться сопоставимого ускорения по сравнению с std::vector без возможности вляпаться в UB.An Update on Writing Memory Safety Bugs
On push_back_unchecked: Performance with FromIterator and Collect
Encapsulating Undefined Behaviour in the C++ Standard Library for Performance with Safety
🔥8❤1
#prog #rust #cpp #article
How (and why) we rewrote our production C++ frontend infrastructure in Rust
"Фронтенд" в данном случае означает прокси-сервер, если что.
How (and why) we rewrote our production C++ frontend infrastructure in Rust
"Фронтенд" в данном случае означает прокси-сервер, если что.
“Should we convert our _ code to Rust?” is a question that comes up a lot. And a lot of the time the right answer is a pretty firm, “No.” So I thought it might be beneficial (and hopefully interesting) to walk through a case where the code involved was incredibly you-cannot-fuck-this-up business-critical and when we asked that question about it, we came back with a yes. Here’s what it was, how we got to that answer, and what we did about it.
The bottom line is that C++ has caused more than a few situations where we wanted to do something or add a feature and it’s just like… that’s a cool idea, but it’s just not worth the uphill battle against the language. And it was to the point where any change carries the risk of unforeseen consequences.
👍1🥰1😁1