boost::iterator_adaptor
Hi, I am trying to write my own iterator - class and using for that the boost::iterator_adaptor. I could find on the webpage several examples of how to connect an existing iterator like std::string::iterator or a simple array as "base-class" for my new iterator, but what can I do if I dont have any base-iterator? In the documentation I found the following sentence: "The Iterator Adaptor library allows you transform an arbitrary ``base'' type into a standard-conforming iterator with the behaviors you choose. Doing so is especially easy if the ``base'' type is itself an iterator." In my situation I dont have any base type which is an iterator, so how should I now create such a base-type? Which are the specifications of such a base-type? Where can I get information on how to create a new base-type? I am trying to write an iterator which reads records from a file or a database and always when I do the it++ the next record is read from the file or database. Thanks a lot in advance Julia
--- At Fri, 29 Nov 2002 17:54:08 +0100, Julia Donawald wrote:
Hi,
I am trying to write my own iterator - class and using for that the boost::iterator_adaptor. I could find on the webpage several examples of how to connect an existing iterator like std::string::iterator or a simple array as "base-class" for my new iterator, but what can I do if I dont have any base-iterator? In the documentation I found the following sentence: "The Iterator Adaptor library allows you transform an arbitrary ``base'' type into a standard-conforming iterator with the behaviors you choose. Doing so is especially easy if the ``base'' type is itself an iterator." In my situation I dont have any base type which is an iterator, so how should I now create such a base-type? Which are the specifications of such a base-type? Where can I get information on how to create a new base-type?
The base-type is only there for your reference. All references to the base type are made using the Policy class. Simply specify the int as your base type and then implement the Policy class accordingly. You can look at the default policy class for the functions that you need to implement. The default policy class is a good starting point for an iterator-like base class, otherwise it makes a good example of what functions to implement. It took me a while to understand this arrangment but once you understand that the base is for your policy, then it becomes clearer. The policy class basically operates on the base class. The base class maintains the "position" and reference information about the iterator. Good luck. ...Duane
"Julia Donawald"
Hi,
I am trying to write my own iterator - class and using for that the boost::iterator_adaptor. I could find on the webpage several examples of how to connect an existing iterator like std::string::iterator or a simple array as "base-class" for my new iterator, but what can I do if I dont have any base-iterator? In the documentation I found the following sentence: "The Iterator Adaptor library allows you transform an arbitrary ``base'' type into a standard-conforming iterator with the behaviors you choose. Doing so is especially easy if the ``base'' type is itself an iterator." In my situation I dont have any base type which is an iterator, so how should I now create such a base-type? Which are the specifications of such a base-type? Where can I get information on how to create a new base-type?
I am trying to write an iterator which reads records from a file or a database and always when I do the it++ the next record is read from the file or database.
You might look at the counting iterator adaptor which can use an int as a Base type. -Dave -- David Abrahams dave@boost-consulting.com * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
participants (3)
-
David Abrahams
-
Duane Murphy
-
Julia Donawald