求字符串2是是否是字符串1的字串

template<typename T>
T my_search(T first1, T last1, T first2, T last2)
{
    int d1 = distance(first1, last1);
    int d2 = distance(first2, last2);
    if(d1 < d2)
    return last1;
    
    T current1 = first1;
    T current2 = first2;
    while(current2 != last2)
    {
        if(*current1 = *current2)
        {
            ++current1;
            ++current2;
        }
        else
        {
            if(d1 == d2)
            {
                return last1;
            }
            else
            {
                current1 = ++first1;
                current2 = first2;
                --d1;
            }
        }
    }
    return first1;
}
原文地址:https://www.cnblogs.com/yi-meng/p/search.html