peltorator's blog

By peltorator, 7 months ago, In English

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?

  • Vote: I like it
  • +47
  • Vote: I do not like it

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Time to drop my own zip and enumerate functions :)

Spoiler
»
7 months ago, # |
  Vote: I like it +21 Vote: I do not like it

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

  • »
    »
    7 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      7 months ago, # ^ |
        Vote: I like it +24 Vote: I do not like it

      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.