p******g 发帖数: 347 | 1 Since std::set::iterator only support ++ and --, i write a piece of code to do
the + (and -) functionality.
the code is below:
set::const_iterator& operator+(set::const_iterator& it, const int& n
)
{
for (int i=0; i
return it;
}
it works fine. But only for set. I want to write a generic function, the
code is
template
set::const_iterator& operator+(set::const_iterator& it, const int& n)
{
for (int i=0; i
return it;
}
Even more gene | t*q 发帖数: 104 | 2 why not use the built-in "advance" function?
do
n
the
【在 p******g 的大作中提到】 : Since std::set::iterator only support ++ and --, i write a piece of code to do : the + (and -) functionality. : the code is below: : set::const_iterator& operator+(set::const_iterator& it, const int& n : ) : { : for (int i=0; i: return it; : } : it works fine. But only for set. I want to write a generic function, the
| p******g 发帖数: 347 | 3 yeah right, surely you can use it but what if there is no advance?
hehe just for the sake of pedagogy, how to solve the problem?
I come up with an ugly solution
template
struct MyIter : T::iterator {
MyIter(const T& a) : T::iterator(a.begin()) {};
MyIter& operator+(const int& n);
};
template
MyIter& MyIter::operator+(const int& n)
{
for (int i=0; i
return *this;
}
Any better idea? it seems I can't use "T::iterator &" why?
【在 t*q 的大作中提到】 : why not use the built-in "advance" function? : : do : n : the
| p***o 发帖数: 1252 | 4 you need 'typename', i.e,
typename std::set::const_iterator &it
do
n
the
【在 p******g 的大作中提到】 : Since std::set::iterator only support ++ and --, i write a piece of code to do : the + (and -) functionality. : the code is below: : set::const_iterator& operator+(set::const_iterator& it, const int& n : ) : { : for (int i=0; i: return it; : } : it works fine. But only for set. I want to write a generic function, the
| p******g 发帖数: 347 | 5 cool.
thanks that resolved the problem.
【在 p***o 的大作中提到】 : you need 'typename', i.e, : typename std::set::const_iterator &it : : do : n : the
|
|