Re: how return a iterator?
On Mar 17, 9:04 pm, "antani" <antani8...@yahoo.it> wrote:
VolumeType::ISetType::iterator findFirstIteratorMarked(const
VolumeType::ISetType::iterator & it,const
VolumeType::ISetType::iterator & e_it)
{
VolumeType::ISetType::iterator _it=it;
while (_it!=e_it)
{
if ((*_it).mark) return _it;
else _it++;
}
}
I get compiler error.....
You have not declared any return statement outside the 'while' loop
which might be the reason for the error you get.
either add a return statement outside the loop or if you are using
microsoft vc,declare your function as '__declspec(noreturn)'.
Hi,
I would like do a function that give a iterator to vector stl return
the first element after of iterator where
the field mark is true.How can I do it?
e_it is v.end() where v is a stl vector.
#include <algorithm>
and use 'std::find_if' like this:
/*assuming that 'VolumeType::ISetType::iterator' points to objects of
type 'vtype'*/
typedef std::vector<vtype> my_vec;
bool Ismarked(const my_vec::value_type& x){/*
my_vec::value_type==vtype */
return x.mark;
};
bool Is_not_marked(const vtype& x){/* my_vec::value_type==vtype */
return !x.mark;
};
{//somewhwere in your code:
const VolumeType::ISetType::iterator iter;
iter=std::find_if(v.begin(),v.end(),Ismarked);/*find first marked
element*/
iter=std::find_if(v.begin(),v.end(),Is_not_marked);/*find first
none-marked element*/
};