samedi 22 mai 2021

More templates in C++?

My assignment is to make a multimap_util template class that helps the using of multimap. My main problem is that the multimap_util class should also work with custom sorted multimaps.

I don't know how to make it work with two different templates.

So with 2 template args like this:

std::multimap<int, int> m;
multimap_util<int, int> mu( m );

and with 3 template args like this:

std::multimap<std::string, std::string, string_size_more> lmm;
multimap_util<std::string, std::string, string_size_more> lmmu( lmm );

Here is my code:

template <typename T1, typename T2, typename C>
class multimap_util
{
        std::multimap<T1, T2, C>* map;
        
    public:
        multimap_util(std::multimap<T1,T2>& map) : map(&map)
        {};
        
        multimap_util(std::multimap<T1,T2,C>& map) : map(&map)
        {};
.
.
.
}

I always get errors like this:

error: wrong number of template arguments (2, should be 3)
   66 |   multimap_util<std::string, std::string> langsu( langs );

It has to be done without variadic template.

I red about template partial specialization but I don't know how it works. I also thought about making a child class with a different template that derives from the util class?

Aucun commentaire:

Enregistrer un commentaire