Why in the associative array can only non-constant cards, such as images, be used?
Because these operators return a reference to the object associated with a particular key. If the container does not already contain such an object, operator[] inserts the default object. Now, if the container is persistent, you cannot insert any objects into it, and you cannot return a link to non-existent objects, therefore these operators are available only for mutable containers.
Throwing an exception in this case is possible, of course, but not the best way to approach fairly general cases when an object for a given key does not exist. In principle, exceptions are extremely expensive and are designed for exceptional situations, but above are not, so this is not worth it.
The best way would be to return the iterator, but then the user would have to check if it is "complete", which would make the use case look like a find () call, and therefore useless. Return iterators or pointers are also possible for containers with persistent content, but this confuses semantics a bit and confuses them.
user405725
source share