http___en.wikipedia.org_wiki_IteratorAggregate.xml
1.1 2.1 2.2 2.3 2.4 2.5 2.6 3.1 4.1 5.1 6.1 7.1 8.1 9.1
Итератор (шаблон) Итератор (на английски: Iterator) е поведенчески шаблон за дизайн, който се използва в обектно-ориентираното програмиране. Предоставя начин за последователен достъп до елементите на обект, без да е нужна вътрешна информация за обекта.В компютърно програмиране, итератор е обект, който дава възможност на програмиста да преминават контейнер, особено списъци. Различни видове итератори често са предоставяни чрез интерфейс контейнер. Въпреки, че интерфейса и семантиката на даден итератор са фиксирани, итераторите често се прилагат по отношение на свързаните с тях структури изпълнение на контейнер и често са плътно свързани към контейнера, за да се даде възможност на оперативните семантиката на Итераторът. Имайте предвид, че итератор изпълнява прекосява и също така дава достъп до елементи от данни в контейнер, но не изпълнява итерация (т.е., не без значителна свобода взето с това понятие или с тривиално използване на терминологията). Итератор е поведенчески подобно на курсора на база данни. Примери[редактиране | редактиране на кода] C++[редактиране | редактиране на кода] C#[редактиране | редактиране на кода] // explicit version IEnumerator  iter = list.GetEnumerator(); while (iter.MoveNext()) Console.WriteLine(iter.Current); // implicit version foreach (MyType value in list) Console.WriteLine(value);
1.1 2.1 2.2 2.3 2.4 2.5 3.1 4.1 5.1 6.1 7.1 8.1 9.1 10.1 11.1 11.2 12.1 12.2 12.3 13.1 13.2 14.1 15.1 15.2 15.3 15.4 15.5 16.1 17.1 18.1 19.1 19.2 20.1 21.1 22.1 23.1 24.1 25.1 26.1 27.1 28.1 28.2 29.1 29.2 30.1 31.1 31.2 31.3 32.1 33.1 33.2 34.1 35.1 36.1 37.1 37.2 37.3 38.1 38.2 38.3 39.1 39.2 40.1 40.2 40.3 40.4 41.1 41.2 41.3 42.1 43.1 44.1 44.2 45.1 46.1 46.2 47.1 48.1 49.1 50.1 51.1 52.1 53.1 54.1 54.2 55.1 56.1 57.1 58.1 58.2 58.3 59.1 59.2 60.1 61.1 61.2 61.3 61.4 61.5 61.6 62.1 63.1 64.1 65.1 67.1 67.2 67.3 68.1 69.1 70.1 71.1 71.2 72.1 73.1 74.1 75.1 75.2 76.1 77.1 78.1 78.2 78.3 79.1 80.1 81.1 82.1 83.1 84.1 85.1 86.1 87.1 87.2 87.3 88.1 89.1 90.1 91.1 92.1 93.1 94.1 94.2 94.3 95.1 96.1 97.1 98.1 99.1 100.1 100.2 100.3 101.1 102.1 103.1 104.1 104.2 106.1 107.1 107.2 108.1 109.1 109.2 110.1 111.1 112.1 113.1 113.2 113.3 114.1 115.1 115.2 115.3 115.4 116.1 117.1 118.1 118.2 119.1 119.2 120.1 121.1 122.1 123.1 124.1 125.1 125.2 126.1 127.1 128.1 129.1 129.2 130.1 131.1 132.1 133.1 133.2 133.3 133.4 134.1 135.1 135.2 136.1 136.2 136.3 137.1 138.1 139.1 139.2 140.1 140.2 141.1 142.1 143.1 144.1 144.2 145.1 146.1 147.1 147.2 148.1 149.1 150.1 151.1 152.1 153.1 153.2 153.3 154.1 154.2 155.1 156.1 157.1 158.1 159.1 160.1 160.2 160.3 161.1 162.1 163.1 164.1 165.1 166.1 167.1 167.2 168.1 169.1 169.2 170.1 171.1 172.1 173.1 173.2 174.1 174.2 175.1 176.1 177.1 177.2 177.3 178.1 179.1 180.1 181.1 182.1 182.2 183.1 183.2 184.1 185.1 185.2 185.3 186.1 187.1 187.2 188.1 189.1 190.1 190.2 191.1 192.1 193.1 194.1 195.1 195.2 196.1 197.1 198.1 199.1 200.1 201.1 202.1 203.1 204.1 205.1 206.1 207.1 208.1 209.1 210.1 211.1 211.2 211.3 211.4 212.1 212.2 213.1 213.2 213.3 214.1 215.1 215.2 215.3 216.1 217.1 217.2 217.3 218.1 218.2 218.3 219.1 219.2 219.3 220.1 220.2 221.1 221.2 221.3 221.4 222.1 222.2 222.3 223.1 223.2 223.3 223.4 224.1 224.2 224.3 225.1 225.2 225.3 226.1 226.2 226.3 227.1 227.2 227.3 228.1 228.2 228.3 229.1 229.2 230.1 231.1 231.2 232.1 233.1 234.1 235.1 236.1 237.1 238.1 239.1 240.1 241.1 242.1 242.2
Iterator In computer programming, an iterator is an object that enables a programmer to traverse a container, particularly lists.[1][2][3] Various types of iterators are often provided via a container's interface. Though the interface and semantics of a given iterator are fixed, iterators are often implemented in terms of the structures underlying a container implementation and are often tightly coupled to the container to enable the operational semantics of the iterator. Note that an iterator performs traversal and also gives access to data elements in a container, but does not perform iteration (i.e., not without some significant liberty taken with that concept or with trivial use of the terminology). An iterator is behaviorally similar to a database cursor. Iterators date to the CLU programming language in 1974. Contents - 1 Description - 2 In different programming languages - 3 See also - 4 References - 5 External links Description[edit] External iterators and the iterator pattern[edit] An external iterator may be thought of as a type of pointer that has two primary operations: referencing one particular element in the object collection (called element access), and modifying itself so it points to the next element (called element traversal).[4] There must also be a way to create an iterator so it points to some first element as well as some way to determine when the iterator has exhausted all of the elements in the container. Depending on the language and intended use, iterators may also provide additional operations or exhibit different behaviors. The primary purpose of an iterator is to allow a user to process every element of a container while isolating the user from the internal structure of the container.[2] This allows the container to store elements in any manner it wishes while allowing the user to treat it as if it were a simple sequence or list. An iterator class is usually designed in tight coordination with the corresponding container class. Usually, the container provides the methods for creating iterators. Note that a loop counter is sometimes also referred to as a loop iterator. A loop counter, however, only provides the traversal functionality and not the element access functionality. Generators[edit] One way of implementing iterators is to use a restricted form of coroutine, known as a generator. By contrast with a subroutine, a generator coroutine can yield values to its caller multiple times, instead of returning just once. Most iterators are naturally expressible as generators, but because generators preserve their local state between invocations, they're particularly well-suited for complicated, stateful iterators, such as tree traversers. There are subtle differences and distinctions in the use of the terms "generator" and "iterator", which vary between authors and languages.[5] In Python, a generator is an iterator constructor: a function that returns an iterator. An example of a Python generator returning an iterator for the Fibonacci numbers using Python's yield statement follows: def fibonacci(limit): a, b, c = 0, 1, 0 while c < limit: yield a a, b, c = b, a+b, c+1 for number in fibonacci(100): # The generator constructs an iterator print(number) Implicit iterators[edit] Some object-oriented languages such as C#, C++ (later versions), Delphi (later versions), Go, Java (later versions), Lua, Perl, Python, Ruby provide an intrinsic way of iterating through the elements of a container object without the introduction of an explicit iterator object. An actual iterator object may exist in reality, but if it does it is not exposed within the source code of the language.[4][6] Implicit iterators are often manifested by a "foreach" statement (or equivalent), such as in the following Python example: for value in iterable: print value In Python, an iterable is an object which can be converted to an iterator, which is then iterated through during the for loop; this is done implicitly. Or other times they may be created by the collection object itself, as in this Ruby example: iterable.each do |value| puts value end This iteration style is sometimes called "internal iteration" because its code fully executes within the context of the iterable object (that controls all aspects of iteration), and the programmer only provides the operation to execute at each step (using an anonymous function). Languages that support list comprehensions or similar constructs may also make use of implicit iterators during the construction of the result list, as in Python: names = [person.name for person in roster if person.male] Sometimes the implicit hidden nature is only partial. The C++ language has a few function templates for implicit iteration, such as for_each(). These functions still require explicit iterator objects as their initial input, but the subsequent iteration does not expose an iterator object to the user. Streams[edit] Iterators are a useful abstraction of input streams – they provide a potentially infinite iterable (but not necessarily indexable) object. Several languages, such as Perl and Python, implement streams as iterators. Alternative implementations of stream include data-driven languages, such as AWK and sed. Contrasting with indexing[edit] In procedural languages it is common to use the subscript operator and a loop counter to loop through all the elements in a sequence such as an array. Although indexing may also be used with some object-oriented containers, the use of iterators may have some advantages:[7] - Counting loops are not suitable to all data structures, in particular to data structures with no or slow random access, like lists or trees. - Iterators can provide a consistent way to iterate on data structures of all kinds, and therefore make the code more readable, reusable, and less sensitive to a change in the data structure. - An iterator can enforce additional restrictions on access, such as ensuring that elements can not be skipped or that a previously visited element can not be accessed a second time. - An iterator may allow the container object to be modified without invalidating the iterator. For instance, once an iterator has advanced beyond the first element it may be possible to insert additional elements into the beginning of the container with predictable results. With indexing this is problematic since the index numbers must change. The ability of a container to be modified while iterating through its elements has become necessary in modern object-oriented programming, where the interrelationships between objects and the effects of operations may not be obvious. By using an iterator one is isolated from these sorts of consequences. This assertion must however be taken with a grain of salt, because more often than not, for efficiency reasons, the iterator implementation is so tightly bound to the container that is does preclude modification of the underlying container without invalidating itself. For containers that may move around their data in memory, the only way to not invalidate the iterator is, for the container, to somehow keep track of all the currently alive iterators and update them on the fly. Since the number of iterators at a given time may be arbitrarily large in comparison to the size of the tied container, updating them all will drastically impair the complexity guarantee on the container's operations. An alternative way to keep the number of updates bound relatively to the container size would be to use a kind of handle mechanism, that is a collection of indirect pointers to the container's elements that must be updated with the container, and let the iterators point to these handles instead of directly to the data elements. But this approach will negatively impact the iterator performance, since it must effectuate a double pointer following to access the actual data element. This is usually not desirable, because many algorithms using the iterators invoke the iterators data access operation more often than the advance method. It is therefore especially important to have iterators with very efficient data access. All in all, this is always a trade-off between security (iterators remain always valid) and efficiency. Most of the time, the added security is not worth the efficiency price to pay for it. Using an alternative container (for example a singly linked list instead of a vector) would be a better choice (globally more efficient) if the stability of the iterators is needed. Classifying iterators[edit] Iterator categories[edit] Iterators can be categorised according to their functionality. Here is a (non-exhaustive) list of iterator categories:[8][9] Iterator types[edit] Different languages or libraries used with these languages define iterator types. Some of them are[11] In different programming languages[edit] C# and other .NET languages[edit] Iterators in the .NET Framework are called "enumerators" and represented by the IEnumerator interface. IEnumerator provides a MoveNext() method, which advances to the next element and indicates whether the end of the collection has been reached; a Current property, to obtain the value of the element currently being pointed at; and an optional Reset() method, to rewind the enumerator back to its initial position. The enumerator initially points to a special value before the first element, so a call to MoveNext() is required to begin iterating. Enumerators are typically obtained by calling the GetEnumerator() method of an object implementing the IEnumerable interface. Container classes typically implement this interface. However, the foreach statement in C# can operate on any object providing such a method, even if it doesn't implement IEnumerable. Both interfaces were expanded into generic versions in .NET 2.0. The following shows a simple use of iterators in C# 2.0: // explicit version IEnumerator  iter = list. GetEnumerator(); while (iter. MoveNext()) Console. WriteLine(iter. Current); // implicit version foreach (MyType value in list) Console. WriteLine(value); C# 2.0 also supports generators: a method that is declared as returning IEnumerator (or IEnumerable), but uses the " yield return" statement to produce a sequence of elements instead of returning an object instance, will be transformed by the compiler into a new class implementing the appropriate interface. The C++ language makes wide use of iterators in its Standard Template Library, which provides several different kinds of iterators, including forward iterators, bidirectional iterators, and random access iterators. All of the standard container template types provide a rich and consistent set of iterator types. The syntax of standard iterators is designed to resemble that of ordinary C pointer arithmetic, where the * and -> operators are used to reference the element to which the iterator points, and pointer arithmetic operators like ++ are used to advance the iterator to the next element. Iterators are usually used in pairs, where one is used for the actual iteration and the second serves to mark the end of the collection. The iterators are created by the corresponding container class using standard methods such as begin() and The iterator returned by begin() points to the first element, while the iterator returned by end() is a special value that does not reference any element. When an iterator is advanced beyond the last element it is by definition equal to the special end iterator value. The following example shows a typical use of an iterator. std::vector  items; items.push_back(1); // Append integer value '1' to vector 'items' items.push_back(2); // Append integer value '2' to vector 'items' items.push_back(3); // Append integer value '3' to vector 'items' for (std::vector ::iterator i = items.begin(); i != items.end(); ++i) { // Iterate through 'items' std::cout << *i; // And print value of 'items' for current index } //in C++11 for(auto i:items){ std::cout << i; // And print value of 'items' } // //Prints 123 There are many varieties of iterators each with slightly different behavior, including: forward, reverse, and bidirectional iterators; random-access iterators; input and output iterators; and const iterators (that protect the container or its elements from modification). However, not every type of container supports every type of iterator. It is possible for users to create their own iterator types by deriving subclasses from the standard std::iterator class template. Iterator safety is defined separately for the different types of standard containers, in some cases the iterator is very permissive in allowing the container to change while iterating. Implicit iteration is also partially supported by C++ through the use of standard function templates, such as std::for_each(), std::copy() and std::accumulate(). When used they must be initialized with existing iterators, usually begin and end, that define the range over which iteration occurs. But no explicit iterator object is subsequently exposed as the iteration proceeds. This example shows the use of for_each. ContainerType  C; // Any standard container type of ItemType elements void ProcessItem(const ItemType& I) { // Function that will process each item of the collection std::cout << I << std::endl; } std::for_each(C.begin(), C.end(), ProcessItem); // A for-each iteration loop The same can be achieved using std::copy and std::ostream_iterator std::copy(C.begin(), C.end(), std::ostream_iterator (std::cout, "\n")); A limitation is that this technique does not allow the body of the for-each loop to be declared inline, requiring a function pointer or function object to be declared elsewhere and passed as an argument. This can be partially compensated for by using a library such as Boost and using lambda to implicitly generate function objects with familiar infix operator syntax. However, because Boost is implemented at the library level, rather than intrinsically in the language, certain operations have to be done via workarounds. The current standard of C++, C++11, natively supports lambda function syntax, allowing the function template body to be declared inline. Here is an example of for-each iteration using a lambda function: ContainerType  C; // Any standard container type of ItemType elements // A for-each iteration loop with a lambda function std::for_each(C.begin(), C.end(), [](const ItemType& I){ std::cout << I << std::endl; }); Java[edit] Introduced in the Java JDK 1.2 release, the java.util. Iterator interface allows the iteration of container classes. Each Iterator provides a next() and hasNext() method, and may optionally support a remove() method. Iterators are created by the corresponding container class, typically by a method named The next() method advances the iterator and returns the value pointed to by the iterator. The first element is obtained upon the first call to To determine when all the elements in the container have been visited the hasNext() test method is used. The following example shows a simple use of iterators: Iterator iter = list.iterator(); //Iterator  iter = list.iterator(); in J2SE 5.0 while (iter.hasNext()) { System.out.print(iter.next()); if (iter.hasNext()) System.out.print(", "); } To show that hasNext() can be called repeatedly, we use it to insert commas between the elements but not after the last element. Note that this approach does not properly separate the advance operation from the actual data access. If the data element must be used more than once for each advance, it needs to be stored in a temporary variable. When an advance is needed without data access (i.e. to skip a given data element), the access is nonetheless performed, though the returned value is ignored in this case. For collection types that support it, the remove() method of the iterator removes the most recently visited element from the container while keeping the iterator usable. Adding or removing elements by calling the methods of container (also from the same thread) makes the iterator unusable. An attempt to get the next element throws the exception. An exception is also thrown if there are no more elements remaining ( hasNext() has previously returned false). Additionally, for java.util. List there is a java.util. ListIterator with a similar API but that allows forward and backward iteration, provides its current index in the list and allows setting of the list element at its position. The J2SE 5.0 release of Java introduced the Iterable interface to support an enhanced for (foreach) loop for iterating over collections and arrays. Iterable defines the iterator() method that returns an Iterator. Using the enhanced for loop, the preceding example can be rewritten as for (MyType obj : list) { System.out.print(obj); } Some containers also use the older (since 1.0) Enumeration class. It provides hasMoreElements() and nextElement() methods but has no methods to modify the container. Scala[edit] In Scala, iterators have a rich set of methods similar to collections, and can be used directly in for loops. Indeed, both iterators and collections inherit from a common base trait - scala.collection. TraversableOnce. However, because of the rich set of methods available in the Scala collections library, such as map, collect, filter etc., it is often not necessary to deal with iterators directly when programming in Scala. Java iterators and collections can be automatically converted into Scala iterators and collections, respectively, simply by adding the single line import scala.collection. JavaConversions._ to the file. The JavaConversions object provides implicit conversions to do this. Implicit conversions are a feature of Scala: methods that, when visible in the current scope, automatically insert calls to themselves into relevant expressions at the appropriate place to make them typecheck when they otherwise wouldn't. MATLAB[edit] MATLAB supports both external and internal implicit iteration using either "native" arrays or cell arrays. In the case of external iteration where the onus is on the user to advance the traversal and request next elements, one can define a set of elements within an array storage structure and traverse the elements using the for-loop construct. For example, % Define an array of integers myArray = [1,3,5,7,11,13]; for n = myArray % ... do something with n disp(n) % Echo integer to Command Window end traverses an array of integers using the for keyword. In the case of internal iteration where the user can supply an operation to the iterator to perform over every element of a collection, many built-in operators and MATLAB functions are overloaded to execute over every element of an array and return a corresponding output array implicitly. Furthermore, the arrayfun and cellfun functions can be leveraged for performing custom or user defined operations over "native" arrays and cell arrays respectively. For example, function simpleFun % Define an array of integers myArray = [1,3,5,7,11,13]; % Perform a custom operation over each element myNewArray = arrayfun(@(a)myCustomFun(a),myArray); % Echo resulting array to Command Window myNewArray function outScalar = myCustomFun(inScalar) % Simply multiply by 2 outScalar = 2*inScalar; defines a primary function simpleFun that implicitly applies custom subfunction myCustomFun to each element of an array using built-in function arrayfun. Alternatively, it may be desirable to abstract the mechanisms of the array storage container from the user by defining a custom object-oriented MATLAB implementation of the Iterator Pattern. Such an implementation supporting external iteration is demonstrated in MATLAB Central File Exchange item Design Pattern: Iterator (Behavioral). This is written in the new class-definition syntax introduced with MATLAB software version 7.6 (R2008a) and features a one-dimensional cell array realization of the List Abstract Data Type (ADT) as the mechanism for storing a heterogeneous (in data type) set of elements. It provides the functionality for explicit forward List traversal with the hasNext(), next() and reset() methods for use in a while-loop. PHP[edit] PHP 4 introduced a foreach construct, much like Perl and some other languages. This simply gives an easy way to iterate over arrays. foreach works only on arrays in PHP 4, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. In PHP 5, foreach is allowed on object iterating through all the public members. There are two syntaxes; the second is a minor but useful extension of the first. - Example A foreach (array_expression as $value) { echo "$value\n"; } - Example B foreach (array_expression as $key => $value) { echo "($key)$value\n"; } The Example A loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element). The Example B has the same functionality as above. Additionally, the current element's key (in this case, array_expression) will be assigned to the variable $key on each loop. The Iterator interface is pre-defined in PHP 5 and objects can be customized to handle iteration. class MyIterator implements Iterator { private $var = array(); public function __construct($array) { if (is_array($array)) { $this->var = $array; } } public function rewind() { echo "rewinding\n"; reset($this->var); } public function current() { $var = current($this->var); echo "current: $var\n"; return $var; } public function key() { $var = key($this->var); echo "key: $var\n"; return $var; } public function next() { $var = next($this->var); echo "next: $var\n"; return $var; } public function valid() { $var = $this->current() !== false; echo "valid: {$var}\n"; return $var; } } These methods are all being used in a complete foreach($obj AS $key=>$value) sequence. The methods of Iterators are executed in the following order: rewind() 2. while valid() { 2.1 current() in $value 2.3 key() in $key 2.4 next() } Python[edit] Iterators in Python are a fundamental part of the language and in many cases go unseen as they are implicitly used in the for (foreach) statement, in list comprehensions, and in generator expressions. All of Python's standard built-in collection types support iteration, as well as many classes that are part of the standard library. The following example shows typical implicit iteration over a sequence: for value in sequence: print(value) Python dictionaries (a form of associative array) can also be directly iterated over, when the dictionary keys are returned; or the items method of a dictionary can be iterated over where it yields corresponding key,value pairs as a tuple: for key in dictionary: value = dictionary[key] print(key, value) for key, value in dictionary.items(): print(key, value) Iterators however can be used and defined explicitly. For any iterable sequence type or class, the built-in function iter() is used to create an iterator object. The iterator object can then be iterated with the next() function, which uses the __next__() method internally, which returns the next element in the container. (The previous statement applies to Python 3.x. In Python 2.x, the next() method is equivalent.) StopIteration exception will be raised when no more elements are left. The following example shows an equivalent iteration over a sequence using explicit iterators: it = iter(sequence) while True: try: value = it.next() # in Python 2.x value = next(it) # in Python 3.x except StopIteration: break it = iter(it) print(value) Any user-defined class can support standard iteration (either implicit or explicit) by defining an __iter__() method that returns an iterator object. The iterator object then needs to define a __next__() method that returns the next element and an __iter__() method that returns the next iterator object to use. Python's generators implement this iteration protocol. Ruby[edit] Ruby implements iterators quite differently; all iterations are done by means of passing callback closures to container methods - this way Ruby not only implements basic iteration but also several patterns of iteration like function mapping, filters and reducing. Ruby also supports an alternative syntax for the basic iterating method each, the following three examples are equivalent: (0...42).each do |n| puts n end …and… for n in 0...42 puts n end or even shorter 42.times do |n| puts n end Ruby can also iterate over fixed lists by using Enumerators and either calling their #next method or doing a for each on them, as above. See also[edit] - Iteratee, in which, instead of the developer calling the iterator repeatedly to get new values, the iteratee is called repeatedly to process new chunks of data - an example of inversion of control. - Design pattern - Iteration - Iterator pattern - Range - Visitor pattern References[edit] - ^ Gatcomb, Joshua. "Understanding and Using Iterators". Perl.com. Archived from the original on 2005-06-16. A user-defined iterator usually takes the form of a code reference that, when executed, calculates the next item in a list and returns it. When the iterator reaches the end of the list, it returns an agreed-upon value. - ^ a b Watt, Stephen M. "A Technique for Generic Iteration and Its Optimization" (PDF). The University of Western Ontario, Department of Computer Science. Archived from the original on 2006-09-16. Iterators were introduced as constructs to allow looping over abstract data structures without revealing their internal representation. - ^ Alex Allain. "STL Iterators". Cprogramming.com - Your resource for C and C++. You can think of an iterator as pointing to an item that is part of a larger container of items. - ^ a b "Difference between an external iterator and an internal iterator". CareerRide.COM. Archived from the original on 2009-04-03. An internal iterator is implemented by the member functions of the class which has the iteration logic. An external iterator is implemented by a separate class which can be attached to the object which has iteration logic. The advantage of external iterator is that, many iterators can be made active simultaneously on the existing or same object. - ^ Watt, Stephen M. "A Technique for Generic Iteration and Its Optimization" (PDF). The University of Western Ontario, Department of Computer Science. Archived from the original on 2006-09-16. Some authors use the term iterator, and others the term generator. Some make subtle distinctions between the two. - ^ a b Freeman, Eric; Freeman, Elisabeth; Kathy, Sierra; Bert, Bates (2004). Hendrickson, Mike; Loukides, Mike, eds. "Head First Design Patterns" (paperback) 1. O'REILLY. "index vs iterator". BYTES. Archived from the original on 2006-02-01. An index only can be used for containers that (efficiently) support random access (i.e. direct access to an element at a given position). An iterator is a more general concept. Iterators offer efficient traversal of linked lists, files, and a number of other data structures. It often leads to the generation of more efficient code. - ^ Kevin Waterson. "C++ Iteratoren: Iterator-Kategorien" (in German). cppreference.com. - ^ Kevin Waterson. "Iterators: Concepts". sgi. "Types of iterator: Output vs. input vs. forward vs. random access iterator". stackoverflow. Archived from the original on 2011-03-06. - ^ Kevin Waterson. "Introduction to SPL: Introduction to Standard PHP Library (SPL)". PHPRO.ORG. - ^ Collier, Andrew. "Iterators in R". Retrieved 16 November 2013. - ^ "concurrent_unordered_set Template Class". Intel Threading Building Blocks for Open Source. •The iterator types iterator and const_iterator are of the forward iterator category - ^ "java.util: Interface Iterator : Method Summary". ORACLE. External links[edit] - Java's Iterator, Iterable and ListIterator Explained - .NET interface - Article "Understanding and Using Iterators" by Joshua Gatcomb - Article "A Technique for Generic Iteration and Its Optimization" (217 KB) by Stephen M. Watt - Iterators - Boost C++ Iterator Library - Java interface - PHP: Object Iteration - STL Iterators - What are iterators? - Reference description