C ++ real-source code analysis and algorithm source code analysis

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.