Overloading/specializing STL algorithms for non-local containers (database back end)
What I want to do is, in a separate namespace, define m开发者_运维技巧y own sort(), copy(), etc implementations that work with database tables/views/etc containers instead of in-memory std containers. If I define my own sort() that accepts my custom forward iterator, how does the compiler resolve that? Or, what do I need to do so that it will resolve properly i.e. use my custom sort() instead of std sort(), even though I may be passing in custom iterator types that match the standard iterator type requirements?
If it uses std sort(), it would actually still work, it would just be extremely inefficient because it wouldn't be handing over the sort to the database, whereas my sort() implementation would. I'm just not sure how to properly invoke my sort() over std sort() when they have the same name and accept the same types. I may have missed some details in my description, so please bear with me on bludgeoning my way through this issue.
Also, I found the following question to be the most similar to what I'm asking (mentions ADL and partial specialization), but I'm not sure if it directly addresses my issue or describes the best way to go about doing what I've described: Overloading for_each for specific iterator types
It's actually defined behaviour to specialize std namespace algorithms for your own UDTs.
namespace std {
template<> void sort<sometype::someiterator>(sometype::someiterator begin, sometype::someiterator end) {
...
}
};
Edit: Oopsie Sort instead of sort.
Edit again: Oh man, I wrote something totally wrong. That's not explicit spec syntax at all.
精彩评论