scm_gc_protect_object(function);
Timer *timer = new Timer (++counter, when, function);
- TimerList::iterator it = std::find_if (timers.begin (), timers.end (),
- std::bind1st (timer_sort_p, timer));
-
- if (it != timers.end ())
- timers.insert (it, timer);
- else
- timers.push_back (timer);
+ Utils::push_sorted (timers, timer, timer_sort_p);
return scm_from_int (counter);
#endif
#include <ctime>
+#include <algorithm>
+#include <list>
#include <string>
class Bot;
typedef T* second_argument_type;
typedef bool result_type;
};
+
+ template<typename T, typename C>
+ void push_sorted (std::list<T> & storage, T item, C compare)
+ {
+ typename std::list<T>::iterator it =
+ std::find_if (storage.begin (), storage.end (),
+ std::bind1st (compare, item));
+ if (it != storage.end ())
+ storage.insert (it, item);
+ else
+ storage.push_back (item);
+ }
}
#endif