'left' std::vector of std::set each element in left(which set), trying set union operation set iterating on 'left'.
why following code not working. trying set union of 2 sets.
std::vector<std::set<int> > left(num_nodes); //both leftv , left not empty ....there code here fills them. std::set<int> leftv, dummy; for(std::set<int>::iterator u = leftv.begin(); u != leftv.end() ;u++){ dummy.insert(v); //v integer std::set_union (left[*u].begin(), left[*u].end(), dummy.begin(), dummy.end(), left[*u].begin()); dummy.clear(); } error /usr/include/c++/4.3/bits/stl_algo.h:5078: error: assignment of read-only location ‘__result.std::_rb_tree_const_iterator<_tp>::operator* _tp = int’
you trying overwrite contents of set, giving left[*u].begin() output argument of set_union. elements of set cannot modified, since value determines position in set. if could, need grow container accommodate elements, not overwrite existing ones; , output must not overlap either input range. summarise: can't use set_union insert contents of 1 set another.
if want add contents of dummy left[*u], insert each element:
std::copy(dummy.begin(), dummy.end(), std::inserter(left[*u]));
Comments
Post a Comment