Anzahl Elemente zwischen zwei Iteratoren?? Problem mit std:count_if
-
Problem, will folgenden code:
for(std::list<CVirtTreeList::AllocNode>::iterator it= First_Node(); it != Last_Node(); it++) if(it->m_iLevel == (this->m_iLevel+1)) iChildCount++;mit diesem ersetzen:
bool Equal_Level(const AllocNode &o){ return o.m_iLevel == (this->m_iLevel+1) ? true: false; } iTest = (int) std::count_if(First_Node(),Last_Node(), Equal_Level);fehler (Equal_level):
c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(113): error C2064: term does not evaluate to a function taking 1 arguments
-
schätz mal das liegt daran, dass Equal_Level ne memberfunktion ist und dadurch implizit 2 parameter erhält Equal_Level(this, AllocNode)
-
ja ist ne membefunktion von "AllocNode" wie bekomm ich das sonst hin?
-
Per Funktionsobjekt z.B.
-
hmm... kannst mir mal ein beispiel machen? WEnn ich extra ein Funktionsobjekt anlegen muss, wird sich von der Performance her nichts schenken denk ich....
-
kleiner tipp:
mach das programm erstmal fertig mit funktionierenden methoden. wenns dann zu langsam ist, fang an zu optimieren. und um zu gucken, was das ganze wirklich ausbremst, guck mit nem profiling tool drauf.
brauchst sonst ewig, um was produktives abzuliefern

-
struct foo { foo( const AllocNode& xyz ) : node( xyz ) {} bool operator()( const AllocNode& obj ) const { return obj.m_iLevel == node.m_iLevel+1; } private: const AllocNode& node; }; // ... std::cout << std::count_if( list.begin(), list.end(), foo( deinobjekt ) );
-
bin schon fertig;) un jetzt am optimieren;)
Wie kann ich ein Profiling tool anwenden?