Match rstl::find_by_key.

Thanks anonymous contributor.
This commit is contained in:
Henrique Gemignani Passos Lima 2022-12-09 14:05:49 -03:00
parent 4e0df3d957
commit 572777596d
1 changed files with 10 additions and 8 deletions

View File

@ -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 <typename T>
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<T>());
}
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<T>());
}
} // namespace rstl