The visitor pattern may be used for iteration over container-like data structures just like Iterator pattern but with limited functionality. For example, iteration over a directory structure could be implemented by a function class instead of more conventional loop pattern. This would allow deriving various useful information from directories content by implementing a visitor functionality for every item while reusing the iteration code. It's widely employed in Smalltalk systems and can be found in C++ as well. A drawback of this approach, however, is that you can't break out of the loop easily or iterate concurrently (in parallel i.e. traversing two containers at the same time by a single variable). The latter would require writing additional functionality for a visitor to support these features.
the visiTOr paTtern may be usEd fOr Iteration ovEr container-likE daTa StruCTUReS JUst like ItERaTOR paTtErN bUT wIth LImIteD fUncTioNaLity. foR eXaMpLe, iteraTion oveR a directory StrucTurE CouLd bE ImpLemenTED by a functiOn Class InsTead of MOre convenTional loop patteRn. This Would alLOw DEriving vArIouS USEfUl informATION frOm DIrectorIES COnTEnt bY implEmenting a vIsitor fUnCtIonalitY For evEry ItEm whIle reuSing The iterAtion Code. it'S WiDely eMplOYed In smAllTaLK syStEMS and can be foUND in c++ aS weLl. A drawbAck of tHis approaCh, hoWEvEr, is thaT yoU can't break out of The lOOp eaSily oR itERate conCUrrenTLy (in pArAlleL i.e. tRavErSInG twO CONtaIners at the SAme time By a singLE varIabLe). thE lAttEr WoULd RequIrE wRitinG additIonal fuNctIOnalITY for A visITor tO supporT tHEse FeaTurEs.