I'm trying to write a templetized (templated?) container class that can be sorted. No, STL doesn't work in this case for several reasons that I won't go into now.
The sort()-method should be specialized or overloaded depending on the template parameter used for the container, e.g. an container<int> needs a different sort function than a container<std::string>. So far nothing I have tried has worked and suprisingly I haven't found any tutorials for this use case. This really shouldn't be that hard, I believe but for some reason I can't manage to find a solution.
@coder777: Well, because that would be too easy ;-) Actually, for some reason I haven't thought of that. that would certainly be the easiest way. However, I found a nicer way in the meantime. Functors! I just pass in a functor-type as a template parameter and call that in the sort() function. Works flawlessly, dead easy and nicely expendable. That way you can define a functor pretty much anywhere and it doesn't have to know anything about the internals of the container. It just has to return a bool representing a (partial) order between to instances of the chosen type. I wonder why I didn't think of this earlier!
@MiiniPaa: Looks nice in theory but has been giving me all sorts of headaches. This is probably because my container has two template parameters, type and size. So that would be a partial specialization of a method, which is difficult, from what I know. At least I haven't been able to get it to work. Using functors works like a charm though!
It just has to return a bool representing a (partial) order between to instances of the chosen type. I wonder why I didn't think of this earlier!
Working just like standard library sort() function. It is often used idiom in standard library. You can pass functor to almost any function where comparsion is used.
So that would be a partial specialization of a method, which is difficult, from what I know