I can't find any better way to term it than that. ^^ I'm making a few data structures for my own use and I'm running into a few things.
Just as an example, I have a templated Dictionary/Map data structure. The template parameters are KeyType and ValueType. This data structure has a binary search tree to store node containing keys and values. Because this is a binary search tree, it needs to compare the keys to insert them appropriately.
This is the issue: >, <, ==, >=, <=, !=. All theses operators will not have a consistent or appropriate effect with character-strings.
The solution I've heard is partial template specialization so I can explicitly write the templated method that will be used for said template parameter. However, in my situation, I have two template parameters. I can't seem to find a way to get the compiler to understand that I'm manually writing the templated method that it can then template for different ValueTypes.
template<typename KeyType, typename ValueType>
class MultiDictionary
{
// ...
void Add(KeyType Key, ValueType Value);
// ...
}
template<typename KeyType, typename ValueType>
void MultiDictionary<KeyType, ValueType>::Add(KeyType Key, ValueType Value)
{
// ...
}
template<, typename ValueType>
void MultiDictionary<TCHAR*, ValueType>::Add(TCHAR* Key, ValueType Value)
{
// ...
}
The last method shown is what I thought it might be like, based on single template-parameter partial template-specialization, but no luck. Said code results in a compiler error about having no declaration for said method within the MultiDictionary class.
Am I going to have to copy every single bit of the code over and declare something like:
template<typename KeyType, typename ValueType>
class MultiDictionary
{
// ...
void Add(TCHAR* Key, ValueType Value);
// ...
}
I'm not that familiar with the more complicated aspects of template programming. I also need to figure out how to partially specialize so that my data structures will operate correctly if given pointers or references. I'm trying to avoid run-time type identification. Clearly this can be done at compile time, manually, but using templates, I was hoping to take advantage of reusable code techniques. One source for all templates, besides that partial specialization, instead of declaring and defining multiple data structures for each variation with nearly identical code.