Skip to content

Is it possible to return a non-const iterator from an unordered_set with a custom_key? #2152

Answered by cpplearner
hinchcmark asked this question in Q&A
Discussion options

You must be logged in to vote

As mentioned in the Q&A, non-const element access is intentionally disabled, because modification of elements in a std::unordered_set will change the elements' hash value and thus disrupt the internal organization of std::unordered_set.

In C++17, it is possible to extract nodes from a std::unordered_set, modify their value()s while they are not stored in a container, and then insert them back to the container.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hinchcmark
Comment options

@miscco
Comment options

Answer selected by hinchcmark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants