If I am sure that a certain value is not yet into an unordered_set, and I am going to insert such value, is it correct to pass this set end() iterator as a hint?
EDIT:
Code:
#include <unordered_set>
using namespace std;
unordered_set<int> someset;
int main(){
auto it=someset.find(0);
if(it==someset.end()) someset.insert(it, 0); //correct? possible performance boost if the set is actually populated?
}
I think, you can simply call
insertfunction and the returned value will tell you whether value is inserted, or it is already present in the set.Actually
pis of typestd::pair<iterator,bool>, sop.secondtells you whether value is inserted, or it is already present in the set, andp.firstis the iterator which tells you the position of the value.Remember that this is faster than your approach, because my solution reduces the overall work.