473,725 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comment please: begin() method in container class

Dear all :
I am not good at programming, please give a hand.

My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.

To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:

using std::vector

class container::priv ate vector<DATATYPE >
{

public:
using vector<DATATYPE l>::begin;
}

however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).

To to that, I make the container::begi n() like this :

#inlcude myIterator.h

class container::priv ate vector<DATATYPE >
{

private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}

}

// in myIterator.h , I have:

#include DATATYPE.h

class myIterator {

private:

DATATYPE* current;
............... ......

public:

DATATYPE& operator*()
{
return *current;
}
}

I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.

Thanks in advance.
Sheldon

Dec 8 '06 #1
11 1681
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.

My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.

To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:

using std::vector

class container::priv ate vector<DATATYPE >
{

public:
using vector<DATATYPE l>::begin;

}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).

To to that, I make the container::begi n() like this :

#inlcude myIterator.h

class container::priv ate vector<DATATYPE >
{

private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}

}// in myIterator.h , I have:

#include DATATYPE.h

class myIterator {

private:

DATATYPE* current;
............... ......

public:

DATATYPE& operator*()
{
return *current;
}

}I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.
Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.

--
Erik Wikström

Dec 8 '06 #2

"er****@student .chalmers.se 写é“:
"
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.

My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.

To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:

using std::vector

class container::priv ate vector<DATATYPE >
{

public:
using vector<DATATYPE l>::begin;

}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).

To to that, I make the container::begi n() like this :

#inlcude myIterator.h

class container::priv ate vector<DATATYPE >
{

private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}

}// in myIterator.h , I have:

#include DATATYPE.h

class myIterator {

private:

DATATYPE* current;
............... ......

public:

DATATYPE& operator*()
{
return *current;
}

}I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.

Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.

--
Erik Wikström
Thanks Erik !
I want to do that but actually I can not do it in that way.
Because most behivours of my iterator are different from a "raw pointer
to an array" - like the vector one. For example, the "--" , "++" "+="
etc. all are diffferent, mine iterator is working on a 2-d concept(for
example, a 2-d sub-range area of a 2-d image). But I think the
dereferencing * is the same. So It seems that I can not benefit two
much by wrapping the iterator.

Dec 8 '06 #3
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...

"er****@student .chalmers.se ??:
"
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.

My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.

To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:

using std::vector

class container::priv ate vector<DATATYPE >
{

public:
using vector<DATATYPE l>::begin;

}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).

To to that, I make the container::begi n() like this :

#inlcude myIterator.h

class container::priv ate vector<DATATYPE >
{

private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}

}// in myIterator.h , I have:

#include DATATYPE.h

class myIterator {

private:

DATATYPE* current;
............... ......

public:

DATATYPE& operator*()
{
return *current;
}

}I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.

Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.

--
Erik Wikström
Thanks Erik !
I want to do that but actually I can not do it in that way.
Because most behivours of my iterator are different from a "raw pointer
to an array" - like the vector one. For example, the "--" , "++" "+="
etc. all are diffferent, mine iterator is working on a 2-d concept(for
example, a 2-d sub-range area of a 2-d image). But I think the
dereferencing * is the same. So It seems that I can not benefit two
much by wrapping the iterator.

Well, why don't you just use it as a 2D array then using at() the formula
being:
row * maxrow + column

That is, [2][3] for a 5x5 array would be:
..at( 2 * 5 + 3 );

You don't need to create your own container class, because vector supports
both [index] and .at(index). The different being .at does out of bounds
checking, [index] doesn't.
Dec 8 '06 #4
"Jim Langston 写é“:
"
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...

"er****@student .chalmers.se ??:
"
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.
>
My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.
>
To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:
>
using std::vector
>
class container::priv ate vector<DATATYPE >
{
>
public:
using vector<DATATYPE l>::begin;
>
}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).
>
To to that, I make the container::begi n() like this :
>
#inlcude myIterator.h
>
class container::priv ate vector<DATATYPE >
{
>
private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}
>
}// in myIterator.h , I have:
>
#include DATATYPE.h
>
class myIterator {
>
private:
>
DATATYPE* current;
............... ......
>
public:
>
DATATYPE& operator*()
{
return *current;
}
>
}I am not sure if it is the correct way to do that. Any one can give me
a hand is highly appreciated.
Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.

--
Erik Wikström

Thanks Erik !
I want to do that but actually I can not do it in that way.
Because most behivours of my iterator are different from a "raw pointer
to an array" - like the vector one. For example, the "--" , "++" "+="
etc. all are diffferent, mine iterator is working on a 2-d concept(for
example, a 2-d sub-range area of a 2-d image). But I think the
dereferencing * is the same. So It seems that I can not benefit two
much by wrapping the iterator.

Well, why don't you just use it as a 2D array then using at() the formula
being:
row * maxrow + column

That is, [2][3] for a 5x5 array would be:
.at( 2 * 5 + 3 );

You don't need to create your own container class, because vector supports
both [index] and .at(index). The different being .at does out of bounds
checking, [index] doesn't.

Thank you Jim!
The reason for making a customer container is for the iterator. I agree
what you said. but there is some special situations:
say, accroding to your method, If I need to return an iterator in the
position of [2,3](say for a 5x5 array), then the vector::at() will
return a reference of the DATA in the location [2,3], but what I need a
iterator in [2,3] whose behaviours is customer defined, NOT a reference
of DATA.

Off course, you can get an iterator in [2,3], but as I said, this
iterator you got is an std::vector::it erator type NOT myIterator type,
which means that I cannot get myIterator type iterator by using at(),
then I will not be able to use STL algorithm by passing iterators of
myIterator type.

What do you think?

Thank you.
Sheldon

Dec 8 '06 #5
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ n67g2000cwd.goo glegroups.com.. .
"Jim Langston ??:
"
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...

"er****@student .chalmers.se ??:
"
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.
>
My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine it to
mean "next position within a 2-d range in the object sequence" (my
data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.
>
To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:
>
using std::vector
>
class container::priv ate vector<DATATYPE >
{
>
public:
using vector<DATATYPE l>::begin;
>
}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).
>
To to that, I make the container::begi n() like this :
>
#inlcude myIterator.h
>
class container::priv ate vector<DATATYPE >
{
>
private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}
>
}// in myIterator.h , I have:
>
#include DATATYPE.h
>
class myIterator {
>
private:
>
DATATYPE* current;
............... ......
>
public:
>
DATATYPE& operator*()
{
return *current;
}
>
}I am not sure if it is the correct way to do that. Any one can give
me
a hand is highly appreciated.
Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.

--
Erik Wikström

Thanks Erik !
I want to do that but actually I can not do it in that way.
Because most behivours of my iterator are different from a "raw pointer
to an array" - like the vector one. For example, the "--" , "++" "+="
etc. all are diffferent, mine iterator is working on a 2-d concept(for
example, a 2-d sub-range area of a 2-d image). But I think the
dereferencing * is the same. So It seems that I can not benefit two
much by wrapping the iterator.

Well, why don't you just use it as a 2D array then using at() the formula
being:
row * maxrow + column

That is, [2][3] for a 5x5 array would be:
.at( 2 * 5 + 3 );

You don't need to create your own container class, because vector supports
both [index] and .at(index). The different being .at does out of bounds
checking, [index] doesn't.

Thank you Jim!
The reason for making a customer container is for the iterator. I agree
what you said. but there is some special situations:
say, accroding to your method, If I need to return an iterator in the
position of [2,3](say for a 5x5 array), then the vector::at() will
return a reference of the DATA in the location [2,3], but what I need a
iterator in [2,3] whose behaviours is customer defined, NOT a reference
of DATA.

Off course, you can get an iterator in [2,3], but as I said, this
iterator you got is an std::vector::it erator type NOT myIterator type,
which means that I cannot get myIterator type iterator by using at(),
then I will not be able to use STL algorithm by passing iterators of
myIterator type.

What do you think?

Thank you.
Sheldon

Well, exactly how do you expect your iterator to increment?

If you have a 5 x 5 array, and you are at 2,3, when you increment you expect
it to point to 2,4, right? Increment again, and what should it point to?
You are at the end of the row. Do you want it to point to 3,0?

If this is the behavior you want, then incrementing the normal iterator will
do that exact thing. What other type of behavior would you want?
Dec 8 '06 #6

"Jim Langston 写é“:
"
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ n67g2000cwd.goo glegroups.com.. .
"Jim Langston ??:
"
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...

"er****@student .chalmers.se ??:
"
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.

My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine itto
mean "next position within a 2-d range in the object sequence" (my
data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.

To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:

using std::vector

class container::priv ate vector<DATATYPE >
{

public:
using vector<DATATYPE l>::begin;

}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).

To to that, I make the container::begi n() like this :

#inlcude myIterator.h

class container::priv ate vector<DATATYPE >
{

private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}

}// in myIterator.h , I have:

#include DATATYPE.h

class myIterator {

private:

DATATYPE* current;
............... ......

public:

DATATYPE& operator*()
{
return *current;
}

}I am not sure if it is the correct way to do that. Any one can give
me
a hand is highly appreciated.
>
Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.
>
--
Erik Wikström
Thanks Erik !
I want to do that but actually I can not do it in that way.
Because most behivours of my iterator are different from a "raw pointer
to an array" - like the vector one. For example, the "--" , "++" "+="
etc. all are diffferent, mine iterator is working on a 2-d concept(for
example, a 2-d sub-range area of a 2-d image). But I think the
dereferencing * is the same. So It seems that I can not benefit two
much by wrapping the iterator.

Well, why don't you just use it as a 2D array then using at() the formula
being:
row * maxrow + column

That is, [2][3] for a 5x5 array would be:
.at( 2 * 5 + 3 );

You don't need to create your own container class, because vector supports
both [index] and .at(index). The different being .at does out of bounds
checking, [index] doesn't.


Thank you Jim!
The reason for making a customer container is for the iterator. I agree
what you said. but there is some special situations:
say, accroding to your method, If I need to return an iterator in the
position of [2,3](say for a 5x5 array), then the vector::at() will
return a reference of the DATA in the location [2,3], but what I need a
iterator in [2,3] whose behaviours is customer defined, NOT a reference
of DATA.

Off course, you can get an iterator in [2,3], but as I said, this
iterator you got is an std::vector::it erator type NOT myIterator type,
which means that I cannot get myIterator type iterator by using at(),
then I will not be able to use STL algorithm by passing iterators of
myIterator type.

What do you think?

Thank you.
Sheldon

Well, exactly how do you expect your iterator to increment?

If you have a 5 x 5 array, and you are at 2,3, when you increment you expect
it to point to 2,4, right? Increment again, and what should it point to?
You are at the end of the row. Do you want it to point to 3,0?

If this is the behavior you want, then incrementing the normal iterator will
do that exact thing. What other type of behavior would you want?

That is the problem: it to point to 2,4, Increment again, I don't
want it to point to 3,0, I want it points the next one which is 3, 3,
not 3, 0! to then end of this row, increase one , it points to 4,3 not
4,0.

That is why I have to define my own iterator.

What do you think?

Dec 8 '06 #7

"Jim Langston 写é“:
"
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ n67g2000cwd.goo glegroups.com.. .
"Jim Langston ??:
"
"food4uk" <ca**********@h otmail.comwrote in message
news:11******** **************@ f1g2000cwa.goog legroups.com...

"er****@student .chalmers.se ??:
"
On Dec 8, 2:06 pm, "food4uk" <cai_xiaod...@h otmail.comwrote :
Dear all :
I am not good at programming, please give a hand.

My data structure is very similar as an array. I actually can use the
std::vector as container to organize my data objects. However, the
behaviours of std::vector::it erator can not meet my requirements. I
need to redefine the vector::iterato r's behavious such as ++. It means
"next position in the object sequence" in STL but now I redefine itto
mean "next position within a 2-d range in the object sequence" (my
data
is 2d data). The 2-d range get defined when an iterator get
initialized. Therefore, I think I have to create my own container
class and iterator class.

To reduce my work, I inherit my container class from the std::vector
privately, and try to use the vector::begin() , as it is important for
me to have a begin() in my container, like this:

using std::vector

class container::priv ate vector<DATATYPE >
{

public:
using vector<DATATYPE l>::begin;

}however, I found that the begin() I got from here returns a
vector:iterator type iterator, which is not what I want. I would like
to see that the container::begi n() can return a myIterator type
iterator which enables me to use the customerized definition of its
behivours (such as the definition of "++ "above).

To to that, I make the container::begi n() like this :

#inlcude myIterator.h

class container::priv ate vector<DATATYPE >
{

private:
myIterator pIter;
public:
.....
myIterator begin()
{
*pIter=vector<D ATATYPE>::front ();
return pIter;
}

}// in myIterator.h , I have:

#include DATATYPE.h

class myIterator {

private:

DATATYPE* current;
............... ......

public:

DATATYPE& operator*()
{
return *current;
}

}I am not sure if it is the correct way to do that. Any one can give
me
a hand is highly appreciated.
>
Since you are using a vector you can take advantage of the fact that
it's elements are stored sequentially. However it might be
better/easier to simply make your iterator a wrapper around the
vector's iterator, much like your container.
>
--
Erik Wikström
Thanks Erik !
I want to do that but actually I can not do it in that way.
Because most behivours of my iterator are different from a "raw pointer
to an array" - like the vector one. For example, the "--" , "++" "+="
etc. all are diffferent, mine iterator is working on a 2-d concept(for
example, a 2-d sub-range area of a 2-d image). But I think the
dereferencing * is the same. So It seems that I can not benefit two
much by wrapping the iterator.

Well, why don't you just use it as a 2D array then using at() the formula
being:
row * maxrow + column

That is, [2][3] for a 5x5 array would be:
.at( 2 * 5 + 3 );

You don't need to create your own container class, because vector supports
both [index] and .at(index). The different being .at does out of bounds
checking, [index] doesn't.


Thank you Jim!
The reason for making a customer container is for the iterator. I agree
what you said. but there is some special situations:
say, accroding to your method, If I need to return an iterator in the
position of [2,3](say for a 5x5 array), then the vector::at() will
return a reference of the DATA in the location [2,3], but what I need a
iterator in [2,3] whose behaviours is customer defined, NOT a reference
of DATA.

Off course, you can get an iterator in [2,3], but as I said, this
iterator you got is an std::vector::it erator type NOT myIterator type,
which means that I cannot get myIterator type iterator by using at(),
then I will not be able to use STL algorithm by passing iterators of
myIterator type.

What do you think?

Thank you.
Sheldon

Well, exactly how do you expect your iterator to increment?

If you have a 5 x 5 array, and you are at 2,3, when you increment you expect
it to point to 2,4, right? Increment again, and what should it point to?
You are at the end of the row. Do you want it to point to 3,0?

If this is the behavior you want, then incrementing the normal iterator will
do that exact thing. What other type of behavior would you want?

That is the problem: it to point to 2,4, Increment again, I don't
want it to point to 3,0, I want it points the next one which is 3, 3,
not 3, 0! to then end of this row, increase one , it points to 4,3 not
4,0.

That is why I have to define my own iterator.

What do you think?

Dec 8 '06 #8
On 2006-12-08 17:19, food4uk wrote:
"Jim Langston 写é“:
>Well, exactly how do you expect your iterator to increment?

If you have a 5 x 5 array, and you are at 2,3, when you increment you expect
it to point to 2,4, right? Increment again, and what should it point to?
You are at the end of the row. Do you want it to point to 3,0?

If this is the behavior you want, then incrementing the normal iterator will
do that exact thing. What other type of behavior would you want?


That is the problem: it to point to 2,4, Increment again, I don't
want it to point to 3,0, I want it points the next one which is 3, 3,
not 3, 0! to then end of this row, increase one , it points to 4,3 not
4,0.
Do I understand you correctly that you want it to be a column-iterator
that iterates over a column in your 2d-array? If so then increment is
easy. In fact, as long as you can create some formula for calculating
the next element you can make any kind of iterator you want since the
vector's iterator is random access (a diagonal iterator anyone).

Say you want to iterate over the 3rd column, first create a normal
iterator iter pointing to the beginning of the vector, move the iterator
to the 3rd column (iter += 2) and you are good to go. On increment do
iter += n, where n is the number of columns in the array.

The big question is how you are gonna indicate that you are at the end
of array. One way might be to make your iterator point to vector.end()
after the last element.

--
Erik Wikström
Dec 8 '06 #9

"Erik Wikström 写é“:
"The big question is how you are gonna indicate that you are at the end

"of array. One way might be to make your iterator point to vector.end()

"after the last element.

Hi Erik
I actually use my iterator for a sub-image (arbitrary size rectangle)
with my image.
I use the iterator.operat or ! to indicate the end of my sub-image.

thank you.
sheldon

Dec 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

59
4329
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
5
1807
by: Shane | last post by:
Thanks in advance for the help. I'm new to the STL and havig a bit of trouble figuring out the whole iterator thing. I am using the <list> template and I can insert elements into the list just fine. I just can't get them out. It's like the roach motel! (uh, you can go in, but don't come out... anyway...) Actually, I have been able to get some help from http://www.sgi.com/tech/stl/List.html
5
1198
by: Rich S. | last post by:
I'm reading through records in a file creating bitset objects from them. Each bitset object has a score and I'm trying to collect just the top 2000 scores from over a million records. I tihnk the best way to go is to create a vector, add the objects to it in ascending order while keeping track of the size and lowest score. If the size reaches the 2000 mark then evaluate the score and if it's lower than the lowest score, discard the...
5
2410
by: Franco, Gustavo | last post by:
Hi, I have a question, and please I need a answer. How can I finalize a thread running with Application.Run (I need the message loop!!!) without call Thread.Abort?. I want to call Application.ExitThread in the same thread that it is running.
0
1272
by: faktujaa | last post by:
XML Comment tags (except summary, remarks, param and returns) don't work in my small trial program. The comment tags i want to work are see, seealso, exception, etc. But none of them work. I tried some code from net but no help. Do i have to do some extra settings in the project to make them work. please help. Please check the code below. I don't think i have done any mistakes. Using this code, i build Comment Web Pages and was not able to see...
1
9643
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
0
2183
by: Keith | last post by:
I have a web form that contains a repeater control that is designed to ask like a check book register. Clicking on a certain transaction takes the user to a different .aspx page where it can be edited and then saved. Currently, after saving the edited transaction and returning to the check register, the repeater control table returns to the bottom. I would like the edited transaction to appear in the table instead. I know that a...
0
1889
by: Keith | last post by:
I have a web form that contains a repeater control that is designed to ask like a check book register. Clicking on a certain transaction takes the user to a different .aspx page where it can be edited and then saved. Currently, after saving the edited transaction and returning to the check register, the repeater control table returns to the bottom. I would like the edited transaction to appear in the table instead. I know that a JavaScript...
2
5188
budigila
by: budigila | last post by:
Hiya peeps, Okies, I have been trying to work this out for a while now to no avail... I am a beginner to this whole coding thing but have made great strides in my project. Basically what I am trying to do is to convert an .xml using a .xsl to and using a java script to output it into a readable format within excel. I have been able to successfully use a javascript to combine my .xml and .xsl but cannot figure out how to have it output to...
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.