c++ - Why doesn't unordered_set provide an array access operator -


i'm curious why stl container unordered_set, has constant time complexity random access on average, not provide method accessing elements distance first element in container. example:

t& unordered_set::operator[](size_t index) {     return *(begin() + index); } 

accessing element "by distance" implies there meaningful way measure distance. trouble std::unordered_set is is, well, unordered. hence, there no meaningful way of explaining "some distance beginning" in non-arbitrary way.

if want access distance, copy data vector:

std::vector tmp(unordered.begin(), unordered.end()); 

Popular posts from this blog