C ++ real-source code analysis and algorithm source code analysis
Schemdes:
// TEMPLATE FUNCTION includes WITH PREDtemplate<class _InIt1, class _InIt2, class _Pr> inline bool _Includes(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _Pr _Pred) { // test if set [_First1, _Last1) in [_First2, _Last2), using _Pred for (; _First1 != _Last1 && _First2 != _Last2; ) if (_DEBUG_LT_PRED(_Pred, *_First2, *_First1)) return (false); else if (_Pred(*_First1, *_First2)) ++_First1; else { // advance both ++_First1; ++_First2; } return (_First2 == _Last2); }template<class _InIt1, class _InIt2, class _Pr> inline bool includes(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _Pr _Pred) { // test if set [_First1, _Last1) in [_First2, _Last2), using _Pred _DEBUG_ORDER_PRED(_First1, _Last1, _Pred); _DEBUG_ORDER_PRED(_First2, _Last2, _Pred); return (_Includes(_Unchecked(_First1), _Unchecked(_Last1), _Unchecked(_First2), _Unchecked(_Last2), _Pred)); } // TEMPLATE FUNCTION includestemplate<class _InIt1, class _InIt2> inline bool includes(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2) { // test if all [_First1, _Last1) in [_First2, _Last2), using operator< return (_STD includes(_First1, _Last1, _First2, _Last2, less<>())); }
In The C ++ Standard Library (second edition, 3rd print), it is pointed out that The complexity of this algorithm is at most 2 * (numElems + numSearchElems)-1 comparison.