samedi 4 juillet 2020

Dependent names template question from Stroustrup example

Stroustrup C++ 4th Ed Page 748 has an example of dependent names with regards to member templates. Does anyone know what the dependent name is in this example? Is it all based on the template parameter Alloc?

Thanks!

class Pool { 
public:
    template<typename T>
    T∗ get();
    template<typename T>
    void release(T∗); 
};

template<typename Alloc>
void f(Alloc& all)
{
    int∗ p1 = all.get<int>();
    int∗ p2 = all.template get<int>();
}

void user(Pool& pool)
{ 
    f(pool);
}

Also Stroustrup states that "Compared to the use of typename to explicitly state that a name is assumed to name a type, the use of template to explicitly state that a name is assumed to name a template is rare.". Curious, why would this example be so rare?

Aucun commentaire:

Enregistrer un commentaire