Is it possible to remove elements from an std::unordered_set through bucket iterators?

StackOverflow https://stackoverflow.com/questions/18504858

  •  26-06-2022
  •  | 
  •  

문제

Like the question says, can you remove an element from a std::unordered_set using a bucket iterator (local_iterator)? I can see two possible solutions:

  • Since erase() does only accept global iterators, is there equivalent functionality for local_iterator?
  • Is it possible to obtain the equivalent global iterator for a local_iterator?

If it's not feasible, please elaborate on why it's not.

도움이 되었습니까?

해결책

The obvious answer is no, since there is no function in the interface which supports this. There is also no way to get to an iterator from a local_iterator, for the obvious reason that a local_iterator contains a lot less information. (For most implementations, I suspect that it would be fairly simple to implement erase( local_iterator ), had the standard required it. On the other hand, I can't think of a conceivable use for it, which may be why the standard didn't require it.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top