Jiří Lechner Jiří Lechner - 2 months ago 17
C++ Question

Weird template specification

I have run into this function signature

template<typename T>
template<typename FI>
void vector<T>::_M_assign_aux (FI first, FI last,std::forward_iterator_tag)
{}


Is it equivalent to this one?

template<typename T, typename FI>
void vector<T>::_M_assign_aux (FI first, FI last,std::forward_iterator_tag)
{}


Is there any reason to write it separately?

Answer

_M_assign_aux looks like a method of vector<T>, so this should have started with a code like this:

template<typename T>
class vector
{
    // ...

    template<typename FI>
    void _M_assign_aux(FI first, FI last,std::forward_iterator_tag);

    // ...
};

Looking class declaration, the explanation is more "visible": you have one template declaration for the class, and one for the method.

template<typename T> // template declaration for vector
template<typename FI> // template declaration for _M_assign_aux
void vector<T>::_M_assign_aux(FI first, FI last,std::forward_iterator_tag)
{
}