Choosing the Right Container

You need a container that supports O(1) average lookup by key, maintains insertion order, and allows O(1) removal by key. Which approach works?

A

std::vector<std::pair<K,V>> with a hash index into the vector

B

std::unordered_map, since it maintains insertion order as of C++17

C

std::map — its tree order preserves the sequence elements were added

D

std::unordered_map paired with std::list, cross-referencing each other via stored iterators