
AMDG loadcom wrote:
One step further, will the following version save one copy construction in make_less_by_func()?
template <typename F> struct less_by_func { typedef bool result_type;
const F & func_; less_by_func(const F & func) : func_(func) {}
template<typename T> bool operator()(const T& lhs, const T& rhs) const { return func_(lhs) < func_(rhs); } };
// helper function template<typename F> less_by_func<F> make_less_by_func(const F& func) { return less_by_func<F>(func); }
I don't advise this in general because it requires the argument of
make_less_by_func to survive for a while.
boost::function