Doubt with the concept taught in the video

In the example shown the returntype of the function is given as ForwardIterator, is this a part of C++ STL or is it just a placeholder that we used while writing template<class ForwardIterator, class T>?
Also can you please show me how this function works with an array example, because I’m having a hard time wrapping my head around what exactly is being passed in the function call line from main(). In a normal search function, we generally pass the index, but here it seems like we are passing the value at that particular index. I’m not sure though, please help me with this

Just a place holder

Basically if we are using array then pointers is passed to this function
Call is search(arr,arr+n,value)
Arr points to first element and arr+n points to last

If we are using some STL container then iterators are passed to it
Call is search(con.begin(),con.end(),value)

Hey @chaturvedia336
So u have any other doubt in this ?

So basically iterator is the value at that particular index, right?
And not the index, which we previously used to iterate over our normal search function?
Also can you give me a general idea as to what an iterator is exactly, like what does it hold in terms of generic programming

No iterator is not the value they are similar to pointers ,u can say pointers for stl class containers.

C++ Iterators

Iterators are just like pointers used to access the container elements.

Important Points:

  • Iterators are used to traverse from one element to another element, a process is known as iterating through the container .
  • The main advantage of an iterator is to provide a common interface for all the containers type.
  • Iterators make the algorithm independent of the type of the container used.
  • Iterators provide a generic approach to navigate through the elements of a container.

Advantages:
It is convenient to use iterators rather than using a subscript operator[] to access the elements of a container. If we use subscript operator[] to access the elements, then we need to keep the track of the number of elements added at the runtime, but this would not happen in the case of an iterator.

1 Like

Anything else u wanna ask?

That is petty much it. Thanks a lot

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.