includes:
// TEMPLATE FUNCTION includes WITH PRED 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 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 includes template<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<>())); }
在The C++ Standard Library (second edition, 3rd print)中指出這個算法的復雜度最多是2*(numElems+numSearchElems)-1次比較。