c++ - How to generalize an iterator to a certain type -
Consider these two functions, which work well for std :: vector:
int ConnectNode (GraphNode const and newNode, std :: vector & lt; GraphNode const * & gt; :: launches const_iterator; candidates, std :: vector & GraphNode const *>: const_iterator endCandidates } {Int connections = 0; (Auto IARR = start candids; Iter! = And candidates; ++ Iter) {if (Connectododes (Hydrom, ** Iter)) ++ connection; } Return Connection; } Int connectNode (GraphNode const and newNode, std :: vector & lt; GraphNode & gt; :: const_iterator has been started, std :: vector & gt; GraphNode & gt; :: const_iterator endCandidates} {int connections = 0; (Auto IARR = Start Candidates; Iter! = And Candidates; ++ Iter) {If (ConnectNodes (Nodnod, * IAR)) ++ Connection;} Return Connection;} These functions work well for vectors but not clearly for any vertical containers, eg a set. How to normalize them I can imagine that the only possible solution is that some pretty ugly enabled eef is temporarily. Is there a straight forward solution? Edit: To make it clear: I want both functions, for a normal containers, indicator container's The real logic is inside the connetNodes, which has two references. (Previously the brain in work)
As it was said, type the Iterator a temple T parameter - This iterator fixes the issue of normalization, for the difference between normal GraphNode , and its indication, you can use overloading: Template & lt; Class T & gt; T & amp; Maybe_dirref (T & amp; amp) {return V; } Template & lt; Square T & gt; T & amp; Maybe_Dirfe (T * P) {Return * P; } and just call it in the connectNodes (new node, maybe_dirf (* enter)) .
Comments
Post a Comment