← Back to context

Comment by Joker_vD

8 hours ago

> <map> does the work just fine

It has a rather weird interface, at least until C++ 17 when some of the deficiencies were patched somewhat.

It's a slow generic data structure with an unintuitive API. You can use it for leetcode or for CRUD. For anything more demanding it's horrifically bloated and bad. std::string too. Whenever you see STL datatypes like even string and map, you have to deal with RAII, implicit allocations, weird operator syntax, unexpected mutation (invalidation) and so on.

(Spporting or even encouraging destructive mutation, and by this I mean not incrementing counters or anything harmless but allowing iterator invalidations and crashes, are also why std::vector is bad in my opinion, these are idiomatic APIs for 90s and 2000s programming, which we should know better to avoid in 2026).

  • > For anything more demanding it's horrifically bloated and bad

    C++ containers are designed for average demands. If you need something more specific, you can always use an alternative implementation. And it's better than messing with macros in pure C.

    > you have to deal with RAII

    What's problematic with it?

    > implicit allocations

    Allocations aren't implicit. It's usually clear from the documentation where allocation takes place (like in concatenating strings or copying strings).

    > unexpected mutation (invalidation)

    It's not the case with standard library containers. Mutating methods aren't const-qualified, so that it's clear where mutation can take place. And in C++ it's strictly recommended to mark as const everything in regular user code which shouldn't be mutated.

    • > C++ containers are designed for average demands. If you need something more specific, you can always use an alternative implementation.

      As someone who has been programming exclusively in C/C++ for a long time -- the biggest selling point for these languages in 2026 is exactly being suited to doing something specific, not generic.

      > Allocations aren't implicit

          std::map<int,int> m;
          m[1] = 42; // implicit alloc
          auto m2 = m; // implicit too
      
      

      > in C++ it's strictly recommended to mark as const everything in regular user code which shouldn't be mutated.

      Theory and practice. Making everything const correct is too painful in practice, often impossible. It's a trap for bean counters that can't focus on getting some actual useful work done. I'm being harsh to my own past self here. Counter question: why include allocation mechanics with some existing data that never gets changed? Why should we have to add much more boilerplate to get the simpler thing?

      2 replies →

  • > you have to deal with RAII

    If you find that RAII is a problem, I pity how poor a programmer you must be...

    • You must be very experienced to be so judgemental! But maybe ask the many billions of voxels that get tested per second on my multithreaded and SIMD'ed cutting simulation.

      2 replies →