Given a program that uses an iterator, the task is to find the type of iterator used.
Input : vector.begin()
Output : Random_Access Iterator
Input : list.begin()
Output : Bidirectional Iterator
There are namely five types of iterators present in the C++ Standard Library which are mentioned below:
- Forward Iterator in C++
- Bidirectional_Iterators in C++
- Input iterators in C++
- Output iterator in C++
- Random_access iterators in C++
- Iterator type can be checked by using typeid. typeid is a C++ language operator which returns type identification information at run time. It basically returns a type_info object, which is equality-comparable with other type_info objects.
- Along with it use iterator traits. Traits class defines properties of iterators. Standard algorithms determine certain properties of the iterators passed to them and the range they represent by using the members of the corresponding iterator_traits instantiation.
- Also a iterator category is passed which defines the iterator category the iterator belongs to.
There are five type of tags namely: input_iterator_tag, output_iterator_tag, forward_iterator_tag, bidirectional_iterator_tag, random_access_iterator_tag.
- typename is used along with it to provide a type to the iterator during instanitation.
- Now if the iterator category of the input iterator matches the existing iterator categories the result is displayed.
Time-Complexity: O(1) to find the iterator type
- <iterator> library in C++ STL
- Iterator Invalidation in C++
- Implementing Forward Iterator in BST
- How to delete a range of values from the Set using Iterator
- How to delete a range of values from the List using Iterator
- Implementing Iterator pattern of a single Linked List
- Program to find the Nth term of series -1, 2, 11, 26, 47......
- C Program to find size of a File
- Program to find the Area of an Ellipse
- C++ program to find Machine Epsilon
- Program to find Nth term of series 9, 23, 45, 75, 113...
- C program to find Decagonal Number
- Type of 'this' pointer in C++
- Type Conversion in C++
- Bool data type in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai