Блог пользователя peltorator

Автор peltorator, 6 месяцев назад, По-английски

Ranges and views from c++20 are cool. Today I have learned that C++23 brings even more fun stuff from python to c++. For example, zip and enumerate. These are some of the features from python that I missed the most in c++. Also, now there is a thing called cartesian product which helps one to avoid writing 5 nested loops.

I think these things could be pretty handy for competitive programming, so I would like to ask: what other features of c++23 do you find interesting? And when do you think we could get c++23 on Codeforces?

  • Проголосовать: нравится
  • +47
  • Проголосовать: не нравится

»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Time to drop my own zip and enumerate functions :)

Spoiler
»
6 месяцев назад, # |
  Проголосовать: нравится +21 Проголосовать: не нравится

Deducing this, std::flat_map, std::print

  • »
    »
    6 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I've looked at std::flat_map and didn't understand the point. Is it just worse than std::map?

    • »
      »
      »
      6 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      No. std::flat_map aims to enhance performance, especially for small collections, by utilizing a contiguous memory layout.

    • »
      »
      »
      6 месяцев назад, # ^ |
        Проголосовать: нравится +24 Проголосовать: не нравится

      In some cases, this actually seems useful for finding a balance between time and memory. For example, it seems that it is better to use flat_map when storing edges at the node of a trie.

      As far as I understand this is just an implementation like vector<pair<Key, Value>> with sorted Keys. And it works great with cache.