473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Example of a user-defined forward iterator?

Hi,

I have an octree class that I would like to (slowly) migrate to an
STL-like container. I now need to implement two forward iterators for the
class. I would like to use the iterators in the following manner:

octree<GLfloat>::nodeIterator p;
octree<GLfloat>::itemIterator q;

for (p=foo.begin();p!=foo.end();p++)
{
// bleh
}
(or something reasonably similar). I have reviewed Stroustrup, but have
found the limited examples difficult to adapt to my need. Can anyone
provide an example of a simple container and its iterator?
Thanks,Brett
Jul 19 '05 #1
3 9428
Brett L. Moore wrote:
Hi,

I have an octree class that I would like to (slowly) migrate to an
STL-like container. I now need to implement two forward iterators for the
class. I would like to use the iterators in the following manner:

octree<GLfloat>::nodeIterator p;
octree<GLfloat>::itemIterator q;

for (p=foo.begin();p!=foo.end();p++)
{
// bleh
}
(or something reasonably similar). I have reviewed Stroustrup, but have
found the limited examples difficult to adapt to my need. Can anyone
provide an example of a simple container and its iterator?
Thanks,Brett


Take a look at boost/iterator_adaptors.h. If you can't use it directly,
the source code may give you a hint or two.

Good luck,
Buster

Jul 19 '05 #2

"Thomas Matthews" <to********@sbcglobal.net> wrote in message
news:3F**************@sbcglobal.net...
Brett L. Moore wrote:
Hi,

I have an octree class that I would like to (slowly) migrate to an
STL-like container. I now need to implement two forward iterators for the class. I would like to use the iterators in the following manner:

octree<GLfloat>::nodeIterator p;
octree<GLfloat>::itemIterator q;

for (p=foo.begin();p!=foo.end();p++)
{
// bleh
}
(or something reasonably similar). I have reviewed Stroustrup, but have
found the limited examples difficult to adapt to my need. Can anyone
provide an example of a simple container and its iterator?
Thanks,Brett
Many books on the subject say to inherit from std::forward_iterator.
See the <iterators> header.


Maybe, but I don't believe there is such a class in the standard. I *think*
it may be been in the original STL implementation but got dropped.

Inheriting from std::iterator is a possibility but not required, I think.

Also, read:
Effective C++
More Effective C++ {two separate books)
by Scott Meyers

The Standard Template Libary
by Josuttis


Especially the latter, I would say.

john
Jul 19 '05 #3
> (or something reasonably similar). I have reviewed Stroustrup, but have
found the limited examples difficult to adapt to my need. Can anyone
provide an example of a simple container and its iterator?

The clearest conceptual discussion of forward iterators and containers
I've found was in Stepanov's (the creator of STL) old site:

http://www.sgi.com/tech/stl/
http://www.sgi.com/tech/stl/ForwardContainer.html
http://www.sgi.com/tech/stl/ForwardIterator.html

The definitions may be a little dated since STL got munged into the
C++ Standard Library, but I found the site invaluable when I wanted to
implement my own iterators. It has subtleties like what is
"past-the-end" etc. which you wouldn't otherwise get from just reading
code.
Jul 19 '05 #4

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

Similar topics

12
OOP
by: demon_slayer2839 | last post by:
Hey yall, I'm new to Python and I love it. Now I can get most of the topics covered with the Python tutorials I've read but the one thats just stumping me is Object Orientation. I can't get the...
13
by: vbmax | last post by:
Hi to all! I have to write the following program. 1.User inputs a number (example: 5) 2.Then (because he entered 5) he enters 5 times, each time different, 3-placed number (example: 134, 256,...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
6
by: Bob Sparks | last post by:
Can some one post an example, or where to find one, using DBINFO in a SQL procedure? I can't seem to find one anywhere. I don't see the linkage between the structure and the SQL language variables...
1
by: ramonred | last post by:
Hi, I am following along an example from the book <b>Beginning Visual Web Programming in C#</b> My environment is this: IIS 5.1 on XP Pro, I have the checkbox 'use windows integrated...
3
by: John Salerno | last post by:
Ok, I've been staring at this and figuring it out for a while. I'm close to getting it, but I'm confused by the examples: (?(id/name)yes-pattern|no-pattern) Will try to match with yes-pattern if...
7
by: Ole | last post by:
Hi, I'm going to develop a socket communication between an instrument (running CE 5.0 with Compact Fraework V2) and a PC. As the instrument should only connect to one PC at a time I believe that...
6
by: PythonistL | last post by:
Hello, I would like to improve my web project with javascript for this task: I have a form where users must choose a main category( presented by a drop-down menu) and according to this main...
1
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I have an VC++ MFC Win32 application that isn't working correctly when I build it with VS2005. The problem seems to be in some ADO ActiveX controls that came with VS6 and are now out of support....
5
by: Gav | last post by:
I'm writing a windows application (using C# VS 2005 Pro) to access a MS SQL database and although it is working fine (up to now) I'm not sure I'm going about it in the best way. Can anybody point...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.