Add indirect comparison predicate
authorclinton <clinton@unknownlamer.org>
Thu, 13 Nov 2008 11:25:57 +0000 (11:25 +0000)
committerclinton <clinton@unknownlamer.org>
Thu, 13 Nov 2008 11:25:57 +0000 (11:25 +0000)
* Used to sort containers of pointers using the pointed to objects'
  comparison methods

source/Utils.H

index c1b4741..ff1f6d7 100644 (file)
@@ -1,6 +1,6 @@
 // Utils.H  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (c) 2002,2005 Clinton Ebadi
+// Copyright (c) 2002,2005,2008 Clinton Ebadi
 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -67,6 +67,19 @@ namespace Utils {
   std::string scm2str (SCM);
   SCM str2scm (std::string);
 #endif
+
+  // Class to compare *i1 / *i2 in heaps etc.
+  template<typename T, typename C> class IndirectPred
+  {
+    C compare;
+  public:
+    bool operator() (const T * i1, const T * i2) const
+    { return compare (*i1, *i2); }
+
+    typedef T* first_argument_type;
+    typedef T* second_argument_type;
+    typedef bool result_type;
+  };
 }
 
 #endif