From 6b69dfc5de238057d595bf7e1b03e90cd8f112e1 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 9 Dec 2022 14:05:49 -0300 Subject: [PATCH] Match rstl::find_by_key. Thanks anonymous contributor. Former-commit-id: 572777596dad33f5b428192a7f6a36781c5d5778 --- include/rstl/algorithm.hpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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