C++字符串按照指定规则切割的功能模板类,常用的一段检测记录运行时间的代码

template <typename T>

struct vector_split

{

    typedef typename std::vector<T>::iterator its;

     void operator()(std::vector<T>& data,std::vector<T>& seprate,std::vector<its>& result)

     {

        std::vector<int> ab;

        

        its ini;

        result.clear();

        its i=data.begin(),itend=data.end();

         its first=ini,second=ini;

        its aim_f =seprate.begin(),aim_e=seprate.end();

        while(i!=itend)

        {

            

            while(i!=itend &&

                  (std::find_if(aim_f, aim_e, [&](const T& T_va){return T_va == *i;})!=aim_e)

                  ) ++i;

            first=i;

            while(i!=itend &&

                  (std::find_if(aim_f, aim_e, [&](const T& T_va){return T_va == *i;})==aim_e)

                  ) ++i;

            second=--i;++i;

            

            if(first!=ini && first !=itend){

                result.push_back(first);

                result.push_back(second);

               first =ini;second=ini;

            }

 

        }

 

    }

};

auto start = std::chrono::high_resolution_clock::now();

 

//耗时操作

 

auto stop = std::chrono::high_resolution_clock::now();

 

auto time_consume=stop-start;

std::cout<<j<<" computing time  :"<<time_consume.count()<<"mileseconds"<<std::endl;

原文地址:https://www.cnblogs.com/sofard/p/10450808.html