Search code examples
c++templatesboostpartial-specialization

How can I partially specialize a existing template class into a new type?


----IMPORTANT: This is not a solution for a partial template specialisation but rather I was looking for a type alias without knowing it. Sorry for the confusion-----

What I want to do

I want to specialize boost::unordered_multimap to essentially only require the data that will be stored and therefore make the key permanentally a boost::uuids::uuid.

Current attempt

template<class t>
boost::unordered_multimap<boost::uuids::uuid, t, boost::hash<boost::uuids::uuid>> unorderedUUIDMultMap;'

    Here is the usage:
        unorderedUUIDMultMap<int> uuidMultMap; //Should create a mutlimap storing ints.

Here is the error:

main.cpp|24|error: expected ';' before 'uuidMultMap'|

I also tried to use "typedef" before template but that also didnt work out.

How can I properly do this simple shortcut?


Solution

  • What you want is not a partial specialization, but template type alias:

    template <typename T> using my_mmap = boost::unordered_multimap<boost::uuids::uuid, T, boost::hash<boost::uuids::uuid>>;