 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Markus Breuer Guest
|
Posted: Wed Sep 03, 2003 12:36 pm Post subject: Re: Iterator kompatibel machen |
|
|
| Quote: | ggf würde es schon reichen, den Kontruktor der Klasse einfach zur Template
Funktion zu machen:
[...] |
Anmerkung: Obwohl member-templates zu iso c++ gehören, werden sie nicht
von jedem Compiler unterstützt. Ggf. im Vorfeld prüfen, ob die
Zielplatform sie unterstützt. Andernfalls bleibt dir nur eine
Design-Änderung. Unschön aber (leider) nicht immer vermeidbar!
Gruß Markus
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Joerg Barfurth Guest
|
Posted: Wed Sep 03, 2003 8:43 pm Post subject: Re: Iterator kompatibel machen |
|
|
Hallo Christian,
Christian Sulzer <sulzer1 (AT) utanet (DOT) at> wrote:
| Quote: | namespace fbcont {
template <class T
class MemMappedList {
public:
class iterator {
// ...
};
friend class iterator;
MemMappedList (const char *filename, iterator first, iterator last);
};
} // namespace fbcont
Der Iterator verhält sich wie ein bidirectional-iterator.
Jetzt möchte ich aber den Konstruktor der Klasse auch mit Iteratoren von
STL-Containern (z.b. std::list) füttern können, z.B.:
std::list
// .. mylist irgendwie mit Daten füllen
fbcont::MemMappedList <int> fbmylist ("test.txt", mylist.begin (),
mylist.end ());
Wie kann man die Iteratorklasse STL-kompatibel machen ?
|
Deine Iteratorklasse machst du STL-kompatibel, indem du ihr eine Reihe
von typedefs spendierst (oder von std::iterator<...> ableitest) und
sicherstellst, dass der Iterator auch sonst alle Requirements für den
gewählten Iteratorentyp erfüllt.
Das hilft dir aber mit deinem Problem nicht. Grundsätzlich sind
verschiedene Iteratorklassen nicht (jedenfalls nicht über Vererbung)
verwandt. Wenn dein Konstruktor also beliebige 'STL-kompatible'
Iteratoren akzeptieren können soll, dann muss es ein Konstruktortemplate
sein:
template <class T>
template <class It>
MemMappedList<T>::MemMappedList(char const* filename,
It first, It last)
{ /* ... */ }
HTH, Joerg
--
Jörg Barfurth [email]barfurth (AT) gmx (DOT) net[/email]
<<<<<<<<<<<<< using std::disclaimer; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
Software Developer http://util.openoffice.org
StarOffice Configuration # Deutsch:http://de.openoffice.org
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|