[C++-sig] bad iterator related warning
Nikolay Mladenov
nickm at sitius.com
Thu Oct 30 19:41:05 CET 2003
I updated from the CVS and now I am getting scary warning
wherever I have used python::iterator<>:
d:\shared\boost_1_31_0\boost\boost\python\object\iterator.hpp(66) :
warning C4172: returning address of local variable or temporary
d:\projects\boost_1_31_0\boost\boost\python\object\iterator.hpp(63) :
while compiling class-template member function 'struct OBJ &__thiscall
boost::python::objects::iterator_range<struct
boost::python::return_value_policy<struct boost
::python::return_by_value,struct
boost::python::default_call_policies>,struct
OBJARR::iterator>::next::operator ()(struct
boost::python::objects::iterator_range<struct
boost::python::return_value_policy<struct
boost::python::return_by_value,struct b
oost::python::default_call_policies>,struct OBJARR::iterator> &)'
the sample code reproducing it follows
Thanks,
Nikolay Mladenov
#include <boost/python.hpp>
struct OBJ{
public :
OBJ(int p=0):prop(p){}
int prop;
};
struct OBJARR{
struct iterator : std::iterator<std::input_iterator_tag, OBJ>{
bool operator == (const iterator &other)const {return other.p==p;}
bool operator != (const iterator &other)const {return other.p!=p;}
OBJ operator *() const {return *p;}
iterator &operator ++() {++p; return *this;}
iterator operator ++(int) {iterator res = *this ; ++p; return res;}
iterator(int *ptr):p(ptr){}
private:
int *p;
};
iterator begin() { return iterator(p); }
iterator end() { return iterator(p+10); }
private:
int p[10];
};
namespace python = boost::python;
BOOST_PYTHON_MODULE(iter)
{
python::class_<OBJ>("OBJ", python::init<int> ());
python::class_<OBJARR>("OBJARR")
.def("__iter__",
python::iterator<OBJARR,python::return_value_policy<python::return_by_value>
>() );
;
}
More information about the Cplusplus-sig
mailing list