473,322 Members | 1,526 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,322 software developers and data experts.

STL inherit from container<T>::iterator

Hi,

I'm currently struggling with a design decision. One of my classes
(named Attributable) has a protected member of type

std::list<StrongReference<Attribute> >

Basically the list has strong references that point to Attribute's.
In Attributable i want to provide an stl like interface for
bidirectional iterators like:

Iterator Attributable::attributes_begin();
Iterator Atrributable::attributes_end();

I could easily typedef Iterator as std::list<StrongReference<Attribute>
::iterator. However,

I certainly don't want to have the user of Attributable to access the
strong reference instance.
I rather want to hide the fact that there are strong references
maintained and only provide him access to the actual Attribute pointer.

To accomplish this, the only way that comes up into my mind is to
inherit from
std::list<T>::iterator and override the operators * and ->. However
since i don't have knowledge about internals of the
std::list<T>::iterator, I doubt that this is a good idea.

Any suggestions, links etc.?
Thanks in advance,
Christoph

Apr 3 '06 #1
2 2651
In article <11**********************@i40g2000cwc.googlegroups .com>,
"Christoph Heindl" <ch**************@gmail.com> wrote:
Hi,

I'm currently struggling with a design decision. One of my classes
(named Attributable) has a protected member of type

std::list<StrongReference<Attribute> >

Basically the list has strong references that point to Attribute's.
In Attributable i want to provide an stl like interface for
bidirectional iterators like:

Iterator Attributable::attributes_begin();
Iterator Atrributable::attributes_end();

I could easily typedef Iterator as std::list<StrongReference<Attribute>
::iterator. However,

I certainly don't want to have the user of Attributable to access the
strong reference instance.
I rather want to hide the fact that there are strong references
maintained and only provide him access to the actual Attribute pointer.

To accomplish this, the only way that comes up into my mind is to
inherit from
std::list<T>::iterator and override the operators * and ->. However
since i don't have knowledge about internals of the
std::list<T>::iterator, I doubt that this is a good idea.

Any suggestions, links etc.?


Inheriting from a standard iterator is a bad idea. It is likely that any
code you put in the class would be just as useful for any of the other
standard iterators (other containers could hold StrongReferences as
well. Best would be to write a class that contains the list::iterator
and have your class create one of them with the iterator inside it.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Apr 3 '06 #2
hi Daniel,

thanks for hint. Seems like a very reasonable idea. I gonna give it a
try!

best regards,
christoph

Apr 4 '06 #3

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

Similar topics

9
by: Harald Grossauer | last post by:
Usually STL containers have something like "iterator container<>::erase(iterator)" which erases the element the iterator points to and returns another valid iterator. Set does not have this,...
14
by: Neil Zanella | last post by:
Hello, I would like to ask how come the design of C++ includes std::pair. First of all I don't think many programmers would use it. For starters, what the first and second members are depends...
3
by: red floyd | last post by:
I have a suggestion for the standard library.... This is sort of a combination of std::transform() and std::for_each(). It applies the binary function to each iterator in ...
7
by: Dave | last post by:
Hello all, I'm pondering why the default underlying container for std::priority_queue<> is std::vector<>. It would seem that inserts are liable to happen anywhere, which would make std::list<>...
8
by: Neil | last post by:
Hello, Is there a standard or recommended way of handling deletion and removal of objects in STL. I have loads of list of classes by pointer. e.g. If I have a list<int*>, how should I delete...
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
8
by: Steve Edwards | last post by:
Hi, 1) I'm making a container for string pointers... set<string*> strSet; strSet.insert(...); // insert some strings ....
4
by: lutorm | last post by:
Hi all, I'm having a problem writing template functions that take vector<T>::iterator as arguments and I'm sure you guys can set me straight. Like this: #include<vector> using namespace std; ...
7
by: Renzr | last post by:
I have a problem about the std::set<>iterator. After finding a term in the std::set<>, i want to know the distance from the current term to the begin(). But i have got a error. Please offer me...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.