Subject: CGAL users discussion list
List archive
- From: Leon Nan <>
- To: "new_discuss" <>
- Subject: Comparing an iterator to a NULL value
- Date: Tue, 30 Oct 2007 21:54:10 +0800
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:date:to:subject:message-id:x-mailer:mime-version:content-type:from; b=TD0nJpqZt9Knw0pfi3E17KOVrmhJmQ0vmiJzEApQqnkH+t0B7bQxLC3t1Azonxq9UqOK20Yfcz7DK3FFmljKs/U+OzFfZGPuRmXQDpVyEN60WAS+NjbTDoKJQiy+6nTvR0WhihKmKgURli9SWG2pEbyiIX5aggOCX+FWE5rOAmw=
Comparing an iterator to a NULL
value
Hello, everyone:
I have a problem with iterators in a fairly complex polygonal mesh data structure which is implemented using lists of geometric entities. However, the problem in itself is fairly simple: I need to define special iterator values. In particular, I want a null iterator. This is different from end() which means the end of this list. I want an iterator value that is known to just not correspond to any element. It must be possible to compare using == and != and, of course, this special value must be invariant to changes to the data structure. Say the type is list<int> and my special iterator is NULL_INT_LIST_ITERATOR I want to compare like this a == NULL_INT_LIST_ITERATOR and this comparison should return true only if a has previously been assigned my null value. Previously, I did this using ---------------------------------------------- typedef list<int>::iterator IntIter; IntIter NULL_INT_LIST_ITER(0); ---------------------------------------------- This just defines an iterator with an internal null pointer. That works fine in g++ but it is not documented that it should work. Arguably it is ugly. A different solution is this ---------------------------------------------- inline IntIter get_null_int_iter() { static list<int> l; return l.end(); } #define NULL_INT_LIST_ITER get_null_int_iter() ----------------------------------------------- However, this solution does not work in recent version of Microsoft visual studio. The reason *appears* to be that when I compare this iterator value to a different iterator value it is detected that NULL_INT_LIST_ITER belongs to a different list. It seems you can make it work by defining HAS_ITERATOR_DEBUGGING=0. However, the program still does not work - but possibly for different reasons. If you have a better solution, I'd be grateful to hear about it. Thanks Leon Nan
2007-10-30
|
- Comparing an iterator to a NULL value, Leon Nan, 10/30/2007
- Re: [cgal-discuss] Comparing an iterator to a NULL value, Sylvain Pion, 10/30/2007
Archive powered by MHonArc 2.6.16.