Skip to content

Commit

Permalink
Functor concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Aug 20, 2023
1 parent b0412c6 commit 3ae2cc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
10 changes: 5 additions & 5 deletions include/momo/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,12 @@ class HashMap
return mHashSet.Remove(key);
}

template<typename PairPredicate>
requires std::predicate<const PairPredicate&, const Key&, const Value&>
size_t Remove(const PairPredicate& pairPred)
template<internal::conceptPredicate<const Key&, const Value&> PairPredicate>
size_t Remove(PairPredicate pairPred)
{
auto itemPred = [&pairPred] (const KeyValuePair& item)
{ return pairPred(*item.GetKeyPtr(), std::as_const(*item.GetValuePtr())); };
internal::FastCopyableFunctor<PairPredicate> fastPairPred(pairPred);
auto itemPred = [fastPairPred] (const KeyValuePair& item)
{ return fastPairPred(*item.GetKeyPtr(), std::as_const(*item.GetValuePtr())); };
return mHashSet.Remove(itemPred);
}

Expand Down
5 changes: 2 additions & 3 deletions include/momo/HashMultiMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1085,9 +1085,8 @@ class HashMultiMap
return pvMakeIterator(KeyIteratorProxy(hashMapIter), valueIndex, true);
}

template<typename PairPredicate>
requires std::predicate<const PairPredicate&, const Key&, const Value&>
size_t Remove(const PairPredicate& pairPred)
template<internal::conceptPredicate<const Key&, const Value&> PairPredicate>
size_t Remove(PairPredicate pairPred)
{
size_t initValueCount = mValueCount;
Iterator iter = GetBegin();
Expand Down
10 changes: 5 additions & 5 deletions include/momo/TreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,12 @@ class TreeMap
return mTreeSet.Remove(key);
}

template<typename PairPredicate>
requires std::predicate<const PairPredicate&, const Key&, const Value&>
size_t Remove(const PairPredicate& pairPred)
template<internal::conceptPredicate<const Key&, const Value&> PairPredicate>
size_t Remove(PairPredicate pairPred)
{
auto itemPred = [&pairPred] (const KeyValuePair& item)
{ return pairPred(*item.GetKeyPtr(), std::as_const(*item.GetValuePtr())); };
internal::FastCopyableFunctor<PairPredicate> fastPairPred(pairPred);
auto itemPred = [fastPairPred] (const KeyValuePair& item)
{ return fastPairPred(*item.GetKeyPtr(), std::as_const(*item.GetValuePtr())); };
return mTreeSet.Remove(itemPred);
}

Expand Down

0 comments on commit 3ae2cc1

Please sign in to comment.