I have moved on to C++ from C and recently learning STL.
The last line gives pretty long error in STL style(Helpless) Or maybe I am new to templates thats why I find it helpless.
int insert(Forest *forest, int e1) {
Forest::const_iterator te1;
te1 = forest->begin();
te1->insert(e1);
}
int main() {
//some code here
Forest forest = (5, myHash);
insert(&forest, e1);
}
Forest is:
typedef unordered_set<unordered_set<int>, function<size_t(const unordered_set<int>)>> Forest;
EDIT: After trying as one of answers suggested
Forest::iterator te1 = forest->begin();
te1->insert(e1);
It still gives same errors.
In C++11, the items in a std::set
or std::unordered_set
are all const
. You can't insert into one of them, you have to remove it and re-add.
This is because you're determining the position in the parent set by its hash value, which might change if you add a new item to it. It's analogous to the keys in a std::map
being const
.