Programming Tips - MSVC: When std::unordered_map can be used
Date: 2024dec19
Language: C++
Product: MSVC
Q. MSVC: When std::unordered_map<> can be used
A. When I used it inside a class I got
"attempting to reference a deleted function".
The top-voted answer by Barry on Stack Overflow explains the fine points
https://stackoverflow.com/questions/31264984/c-compiler-error-c2280-attempting-to-reference-a-deleted-function-in-visual
A quick rule of thumb for me that works is:
- You can always use std::unordered_map at the file scope
(Good for a cache, etc)
- If you don't want to change you class's move and copy constructors
use std::map instead. Its slower but compiles.