mercredi 24 février 2016

Type-safe template function which takes iterators

I'm writing different sort functions, which take two iterators and sort sequence. I would like to implement them for any kind of vector and make them typesafe, like this:

template <typename T>
void itsort(std::vector<T>::iterator begin, std::vector<T>::iterator end)
{
    // code
}

But due to errors I'm only able to implement something type-unsafe:

template <typename T>
void itsort(T begin, T end)
{
    // code
}

How to implement type-safe template function, which takes two vector iterators?

PS: Currently there is no need in comparator, all sorts work with different types of numbers.

Aucun commentaire:

Enregistrer un commentaire