diff --git a/include/rstl/algorithm.hpp b/include/rstl/algorithm.hpp index c1722072..0efc3bb9 100644 --- a/include/rstl/algorithm.hpp +++ b/include/rstl/algorithm.hpp @@ -135,9 +135,7 @@ template < typename K, typename V, typename Cmp > class pair_sorter_finder< pair< K, V >, Cmp > { public: typedef K key_type; - Cmp cmp; - pair_sorter_finder(const Cmp& cmp) : cmp(cmp) {} bool operator()(const K& a, const pair< K, V >& b) const; @@ -151,6 +149,14 @@ public: }*/ }; +template +inline pair_sorter_finder< T::value_type, less< select1st< typename T::value_type >::value_type > > default_pair_sorter_finder() +{ + less< select1st< typename T::value_type >::value_type > l; + pair_sorter_finder< T::value_type, less< select1st< typename T::value_type >::value_type > > a(l); + return a; +} + template < typename K, typename V, typename Cmp > inline bool pair_sorter_finder< pair< K, V >, Cmp >::operator()(const K& a, const pair< K, V >& b) const { @@ -171,10 +177,8 @@ find_by_key(const T& container, template < typename T > typename T::const_iterator inline find_by_key( const T& container, const typename select1st< typename T::value_type >::value_type& key) { - typedef typename select1st< typename T::value_type >::value_type K; - return binary_find(container.begin(), container.end(), key, - pair_sorter_finder< typename T::value_type, less< K > >(rstl::less< K >())); + default_pair_sorter_finder()); } template < typename T > @@ -184,10 +188,8 @@ find_by_key_nc(T& container, const typename select1st< typename T::value_type >: template < typename T > typename T::iterator inline find_by_key_nc( T& container, const typename select1st< typename T::value_type >::value_type& key) { - typedef typename select1st< typename T::value_type >::value_type K; - return binary_find(container.begin(), container.end(), key, - pair_sorter_finder< typename T::value_type, less< K > >(rstl::less< K >())); + default_pair_sorter_finder()); } } // namespace rstl