From 3873036391716614531 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,66d20309909372f6 X-Google-Attributes: gidf78e5,public From: James Kuyper Subject: Re: STL and set_union algorithm question? (newbie to STL!) Date: 1998/04/17 Message-ID: <35376387.41C6@wizard.net>#1/1 X-Deja-AN: 345083212 Approved: Fergus Henderson Content-Transfer-Encoding: 7bit X-Original-Date: Fri, 17 Apr 1998 10:13:27 -0400 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANTeIFOEDnX0m9pzZAQH7zQF9EcFdncznwfhKMdOzUNs1RqZYzwh+dVg4 P6Sa+zJJHxtVeXbq7AKvmNf+hg9SZK+X =WWtW Newsgroups: comp.std.c++ > James Kuyper writes: > > > Oleg Zabluda wrote: > > > > > > James Kuyper wrote: > > > > : If a non-const iterator were implementable for set<>, then (*i)=b should > > > : be the equivalent of erase(i) followed by an insert(b). This would be of > > > : neglible importance in typical uses of sets, but would allow modifying > > > : algorithms to be applied to sets without being aware of the special > > > : characteristics of sets. > > > > > > You can easily provide such an iterator yourself. Call it > > > replace_iterator. And the corresponding function > > > replacer(Iterator). > > > > > > Just a thought. > > > > What operator overload do you place the insert() call in? > > Let's call the new iterator 'mutable_set_iterator'. > > You can overload mutable_set_iterator::operator= > (const element_type&). > > mutable_set_iterator::operator* can return *this (as > in insert_iterator). > > This is technically possible but: > - IMO changing set::iterator to mutable_set_iterator > is a bad idea > - it breaks the iterator requirements (already broken by > insert_iterator, I know) > If you override mutable_set_iterator::operator*() to return *this, then how do you do the following: void func(mutable_set_iterator i) { (*i)->member_function(); } You could make this work by defining set::iterator to be a mutable_set_iterator derived from T. However, when T is a class type such as 'long' or 'MyClass *', you cannot derive from it. --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]