diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.hh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 1fd89f3a55bf..33b06ca955df 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -303,6 +303,29 @@ bool hasSuffix(const string & s, const string & suffix); void ignoreException(); +/* STL functions such as sort() pass a binary function object around + by value, so it gets cloned a lot. This is bad if the function + object has state or is simply large. This adapter wraps the + function object to simulate passing by reference. */ +template<class F> +struct binary_function_ref_adapter +{ + F * p; + + binary_function_ref_adapter(F * _p) + { + p = _p; + } + + typename F::result_type operator () ( + const typename F::first_argument_type & x, + const typename F::second_argument_type & y) + { + return (*p)(x, y); + } +}; + + } |