Rationale of C# iterators design (comparing to C++)
- by macias
I found similar topic:
http://stackoverflow.com/questions/56347/iterators-in-c-stl-vs-java-is-there-a-conceptual-difference
Which basically deals with Java iterator (which is similar to C#) being unable to going backward.
So here I would like to focus on limits -- in C++ iterator does not know its limit, you have by yourself compare the given iterator with the limit. In C# iterator knows more -- you can tell without comparing to any external reference, if the iterator is valid or not.
I prefer C++ way, because once having iterator you can set any iterator as a limit. In other words if you would like to get only few elements instead of entire collection, you don't have to alter the iterator (in C++). For me it is more "pure" (clear).
But of course MS knew this and C++ while designing C#. So what are the advantages of C# way? Which approach is more powerful (which leads to more elegant functions based on iterators). What do I miss?
If you have thoughts on C# vs. C++ iterators design other than their limits (boundaries), please also answer.
Note: (just in case) please, keep the discussion strictly technical. No C++/C# flamewar.