[C++-sig] Call policies for unreferencing iterator ...

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Thu Jul 10 11:29:53 CEST 2003


I'm writing some templates to automate export of stl stuffs (at least 
some of the stuffs). I hope I'll soon be able to share my work to know 
what you'll think of it. But before that I have a question about the 
iterators. I want to export the STL iterators using a STL-like interface 
(I've already done some work about exporting interators with python 
interface). My concern is : I defined the __call__ method as the 
operator* of the iterator. But I want to return a reference to the 
object (to be able to modify it if the iterator if mutable). The problem 
is with the call policies ! It's not an internal reference, because the 
reference will still be valid after the iterator is destroyed, and it's 
a bad idea to create it as an "existing object" for it will crash if the 
user try to use the pointer after the container is deleted. My problem 
is I don't know how to tie the lifetime of the object with the container 
... and I don't even think it's possible to do that. What would you do ?

I hope I'm clear enough ...


Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 

More information about the Cplusplus-sig mailing list