Created
April 6, 2010 22:58
-
-
Save mwisnicki/358237 to your computer and use it in GitHub Desktop.
TODO: C++ STL comparator adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// external | |
struct Object; | |
bool compare(Object& l, Object& r); | |
std::vector<Object*> objects; | |
// <TODO> | |
template<class T, class Comparator> | |
Comparator<T*> adaptToPtr(Comparator<T&> cmp) { | |
// adapt comparator of T& to T* | |
// must work for both functions and functors | |
} | |
// </TODO> | |
// this should work | |
std::sort(objects.begin(), objects.end(), adaptToPtr(compare)); | |
// and so should this | |
struct Compare { | |
bool operator()(Object& l, Object& r); | |
}; | |
std::sort(objects.begin(), objects.end(), adaptToPtr(Compare)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment