1. Инвалидирование итераторов При vector::erase все итераторы от позиции удаления до end() становятся «битые». Чтобы безопасно отфильтровать и удалить элементы, пользуйтесь erase–remove идиомой:
auto it = std::remove_if(v.begin(), v.end(), [](int x){ return x < 0; }); v.erase(it, v.end());
remove_if сдвигает «хвост» вперёд, но не меняет размер контейнера.
2. reserve vs resize
* v.reserve(n) выделяет память, но не создаёт объектов → size() не меняется, можно безопасно push_back. * v.resize(n) создаёт n элементов, инициализированных значениями по умолчанию.
3. Производительность std::distance На random-access итераторах (например, vector) это O(1), а на bidirectional или forward (например, list) — O(n). Для списков используйте size() (C++11+) или считайте вручную в критичных местах.
4. emplace_back vs push_back При сложных типах emplace_back может избежать лишнего копирования:
v.emplace_back(ctor_arg1, ctor_arg2); // vs v.push_back(MyType(ctor_arg1, ctor_arg2));
5. Памятка про компараторы В set или map ваш компаратор должен задавать строгий-уровень-менее (operator<): если comp(a,b)==true, то comp(b,a) обязан быть false. Иначе — UB.
Быстро, без воды, но с пользой — проверяйте эти моменты в своём коде!
1. Инвалидирование итераторов При vector::erase все итераторы от позиции удаления до end() становятся «битые». Чтобы безопасно отфильтровать и удалить элементы, пользуйтесь erase–remove идиомой:
auto it = std::remove_if(v.begin(), v.end(), [](int x){ return x < 0; }); v.erase(it, v.end());
remove_if сдвигает «хвост» вперёд, но не меняет размер контейнера.
2. reserve vs resize
* v.reserve(n) выделяет память, но не создаёт объектов → size() не меняется, можно безопасно push_back. * v.resize(n) создаёт n элементов, инициализированных значениями по умолчанию.
3. Производительность std::distance На random-access итераторах (например, vector) это O(1), а на bidirectional или forward (например, list) — O(n). Для списков используйте size() (C++11+) или считайте вручную в критичных местах.
4. emplace_back vs push_back При сложных типах emplace_back может избежать лишнего копирования:
v.emplace_back(ctor_arg1, ctor_arg2); // vs v.push_back(MyType(ctor_arg1, ctor_arg2));
5. Памятка про компараторы В set или map ваш компаратор должен задавать строгий-уровень-менее (operator<): если comp(a,b)==true, то comp(b,a) обязан быть false. Иначе — UB.
Быстро, без воды, но с пользой — проверяйте эти моменты в своём коде!
That growth environment will include rising inflation and interest rates. Those upward shifts naturally accompany healthy growth periods as the demand for resources, products and services rise. Importantly, the Federal Reserve has laid out the rationale for not interfering with that natural growth transition.It's not exactly a fad, but there is a widespread willingness to pay up for a growth story. Classic fundamental analysis takes a back seat. Even negative earnings are ignored. In fact, positive earnings seem to be a limiting measure, producing the question, "Is that all you've got?" The preference is a vision of untold riches when the exciting story plays out as expected.
What Is Bitcoin?
Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.