jeudi 1 juin 2017

generic iterators to access elements of vectors without using Templates c++

I am creating a function which should take as input iterators to vector for example:

vector<int> a; foo(a.begin(),a.end())

vector can be of any type

now the simple way to do this is using templates

template <typename Iterator>
void foo(Iterator first, Iterator last) {
for (Iterator it = first; it!=last; ++it) {
    cout<<*it;
}}

I want to know if there is a way to achieve the same functionality without using templates. Since using Templates would force me to include these functions in Header file of a public API which I don't want to. So I wanted to know is there an alternate way to access the iterators without using Templates.

Aucun commentaire:

Enregistrer un commentaire