Prev: Most vexing parse (was: Why you should never use a const& parameter to initialize a const& member variable!)
Next: Compile time hooks, like: AClass<SomeType,Hooks<FunctorOne,FunctorTwo,...> >
From: Edward Diener on 7 Feb 2010 06:01 In the two forms of vector::erase: iterator erase(iterator position); iterator erase(iterator first, iterator last); can the 'iterator' mentioned be a vector::const_iterator, vector::reverse_iterator, or vector::const_reverse_iterator as well as a vector::iterator ? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Mathias Gaunard on 7 Feb 2010 16:09 On 7 f�v, 23:01, Edward Diener <eldiener_no_spam_h...(a)tropicsoft.com> wrote: > In the two forms of vector::erase: > > iterator erase(iterator position); > iterator erase(iterator first, iterator last); > > can the 'iterator' mentioned be a vector::const_iterator, > vector::reverse_iterator, or vector::const_reverse_iterator as well as a > vector::iterator ? No, since it must be an "iterator", and those types aren't convertible to it. You should, however, be able to extract the iterator out of the reverse_iterator using .base(). -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: achp on 7 Feb 2010 16:17 On 8 фев, 02:01, Edward Diener <eldiener_no_spam_h...(a)tropicsoft.com> wrote: > In the two forms of vector::erase: > > iterator erase(iterator position); > iterator erase(iterator first, iterator last); > > can the 'iterator' mentioned be a vector::const_iterator, > vector::reverse_iterator, or vector::const_reverse_iterator as well as a > vector::iterator ? No, it must be an iterator. You can also get iterator from reverse_iterator by calling base(). However, there is no portable way to use a constant iterator here. That may seem logical; the idea of constant iterator is that it cannot be used to alter the container, even though you need a non-const container object to call erase(). -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Daniel Krügler on 9 Feb 2010 01:42 On 8 Feb., 00:01, Edward Diener <eldiener_no_spam_h...(a)tropicsoft.com> wrote: > In the two forms of vector::erase: > > iterator erase(iterator position); > iterator erase(iterator first, iterator last); > > can the 'iterator' mentioned be a vector::const_iterator, > vector::reverse_iterator, or vector::const_reverse_iterator as well as a > vector::iterator ? Additional to the comments from Mathias and achp it is worth noting that from C++0x on you can indeed use vector::const_iterator as function arguments here, because they are just "position values", which are not affected by the iterator capability to modify the referenced data. HTH & Greetings from Bremen, Daniel Kr�gler -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Edward Diener on 10 Feb 2010 02:28
Daniel Kr�gler wrote: > On 8 Feb., 00:01, Edward Diener <eldiener_no_spam_h...(a)tropicsoft.com> > wrote: >> In the two forms of vector::erase: >> >> iterator erase(iterator position); >> iterator erase(iterator first, iterator last); >> >> can the 'iterator' mentioned be a vector::const_iterator, >> vector::reverse_iterator, or vector::const_reverse_iterator as well as a >> vector::iterator ? > > Additional to the comments from Mathias and achp > it is worth noting that from C++0x on you can indeed > use vector::const_iterator as function arguments > here, because they are just "position values", which > are not affected by the iterator capability to > modify the referenced data. Are you saying that in C++0x a const_iterator means that one can not modify the value to which the iterator refers, as opposed to modifying the sequence itself ? In that case will the sequences change, so that possible sequence member functions which modify the sequence, and use an iterator to specify a position in the sequence, will now have const_iterator versions of the modifying member functions ( such as vector::erase ) ? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |