C++ boost::Iterators::Counting Iterators














































C++ boost::Iterators::Counting Iterators



COUNTING ITERATORS:- Counting Iterators can be used in many ways ranging from filling up the arrays from start to end to count the occurrence of any numbers. However  the previous c++98 version of iterators has the limitation of Operator*() which returns the current value of integers. This counting iterator adapts this crucial piece of functionality to whatever it wraps.It can be used not only for integer types but also for any incrementable types.
 In this example we can will see 2 examples 
                                         1. How to use the counting iterator to count, which is similar to the old ways.
                                         2. Here we will fill an array of pointers with counting iterators and then use indirect_iterator to                                                get the values.
                                             lets get started.....
Code:- (Facts to remember)However counting iterator iterates from first(value) to last(value)-1
OUTPUT:- 
    Counting from 5 to 10
    5 6 7 8 9 10.

CODE:-(Facts to REMEMBER)indirection can be used only with boost not previous version.
 
Output:-
PRINTING IT THROUGH DEREFENCING THROUGH indirect_iterator
1 2 3 4 5 6 7 8 9 
Conclusion:- I have explained clearly the use of counting iterators and its importance with respect to the older version hope you have understand it well. happy learning.