std::set eigene compare funktion
-
wenn ich einem std::set eine eigene compare funktion mitgebe, was wird dann erwartet. eine "<" relation?
-
MSDN schrieb:
On a more technical note, the comparison function is a binary predicate that induces a strict weak ordering in the standard mathematical sense. A binary predicate f(x,y) is a function object that has two argument objects x and y and a return value of true or false. An ordering imposed on a set is a strict weak ordering if the binary predicate is irreflexive, antisymmetric, and transitive and if equivalence is transitive, where two objects x and y are defined to be equivalent when both f(x,y) and f(y,x) are false. If the stronger condition of equality between keys replaces that of equivalence, then the ordering becomes total (in the sense that all the elements are ordered with respect to each other) and the keys matched will be indiscernible from each other.
MfG SideWinder
-
thx.
andere frage, um nicht noch nen thread aufzumachen:
darf man aus einem set, welches gerade mittels iterator durchlaufen wird, einträge löschen?
also sowas wie
xyz iter = bla.begin();
for(;iter != bla.end();++iter) bla.erase(iter);
-
da erase den iterator invalidiert, muss das etwas anders aussehen:
for(xyz iter = bla.begin();iter != bla.end();) bla.erase(iter++);abgesehen davon bleiben - wie bei allen node-basierten containern - alle iteratoren bis auf die, die auf ein gelöschtes element zeigten gültig.
-
also ne kopie vom iterator übergeben? warum macht erase so nen schmu?

-
thordk schrieb:
also ne kopie vom iterator übergeben?
Nein, hochzählen, und erase mit dem alten Wert aufrufen.
warum macht erase so nen schmu?

Ich sehe schon, du hast das verstanden.

-
Soweit ich weiß kann gibt iterator.erase einen gültigen iterator zurück also:
while (iterator != xxx.end()) { if (sollgeloeschtwerden(...)) { iterator = iterator.erase(); } }
-
iterator++ nicht vergessen

-
templäd: Falsch, das geht nicht bei std::set und std::map.
-
Nein, hochzählen, und erase mit dem alten Wert aufrufen.
na, das is doch ne kopie
