Topic: set.erase( it1, it2)


Author: Dennis Yelle <dennis51@jps.net>
Date: 2000/11/12
Raw View
Is this legal:

void f( set<char>& a, set<char>& b)
{
  a.erase( b.begin(), b.end());
}

It seems to crash gcc if b is not empty.
If not legal, where does the standard say
that it is not legal?

Here is a complete program:

#include <set>

void f( set<char>& a, set<char>& b)
{
  a.erase( b.begin(), b.end());
}

int main()
{
  set<char> a;
  a.insert('a'); a.insert('b');
  set<char> b;
  b.insert('b'); b.insert('c');
  f(a,b);
}

Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here:
http://table.jps.net/~vert/

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: Pete Becker <petebecker@acm.org>
Date: 2000/11/12
Raw View
Dennis Yelle wrote:
>
> Is this legal:
>
> void f( set<char>& a, set<char>& b)
> {
>   a.erase( b.begin(), b.end());
> }
>
> It seems to crash gcc if b is not empty.
> If not legal, where does the standard say
> that it is not legal?
>

23.1.2/7. The arguments q1 and q2 passed to a.erase(q1, q2) must be
valid iterators to a.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Contributing Editor, C/C++ Users Journal (http://www.cuj.com)

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/11/13
Raw View
Dennis Yelle wrote:
>
> Is this legal:
>
> void f( set<char>& a, set<char>& b)
> {
>   a.erase( b.begin(), b.end());
> }
>
> It seems to crash gcc if b is not empty.
> If not legal, where does the standard say
> that it is not legal?

Section 23.1.2p7 describes the notational conventions used in Table 69:
"... p and q2 are valid iterators to a, q and q1 are valid
dereferenceable iterators to a, [q1,q2) is a valid range ...". Table 69
itself defines only the behavior of a.erase(q1,q2). A conforming
implementation can choose to allow iterators into other containers, and
for some implementations of some containers that is actually feasible,
but the standard doesn't require that it work.
The section describing set incorporates the requirements from Table 69
by reference, but adds none of its own that would make this code legal.

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: jpotter@falcon.lhup.edu (John Potter)
Date: 2000/11/13
Raw View
On Sun, 12 Nov 2000 18:55:47 GMT, Dennis Yelle <dennis51@jps.net> wrote:

> Is this legal:

No.

> void f( set<char>& a, set<char>& b)
> {
>   a.erase( b.begin(), b.end());
> }
>
> It seems to crash gcc if b is not empty.
> If not legal, where does the standard say
> that it is not legal?

23.1.2/7

John

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]