算法库algorithm-8-cxx14

来源:互联网 发布:知乎2017校园招聘 编辑:程序博客网 时间:2024/06/04 19:14

概述

#include <boost/algorithm/cxx14/equal.hpp>//equal#include <boost/algorithm/cxx14/is_permutation.hpp>//is_permutation#include <boost/algorithm/cxx14/mismatch.hpp>//mismatch



测试

#include <laok.h>#include <boost/algorithm/cxx14/equal.hpp>//equal#include <boost/algorithm/cxx14/is_permutation.hpp>//is_permutation#include <boost/algorithm/cxx14/mismatch.hpp>//mismatch#include <boost/array.hpp>JOB_DEFINE(boost_algorithm , equal){boost::array<int,3> seq1 = { 0, 1, 2 };boost::array<int,5> seq2 = { 0, 1, 2, 3, 4 };using namespace boost::algorithm;PS( std::equal ( seq1.begin (), seq1.end (), seq2.begin ()) ); // truePS( std::equal ( seq2.begin (), seq2.end (), seq1.begin ())  ); // Undefined behaviorPS( equal ( seq1.begin (), seq1.end (), seq2.begin (), seq2.end ()) ); // false}JOB_DEFINE(boost_algorithm , mismatch){using namespace boost::algorithm;boost::array<int,6> c1 = { 0, 1, 2, 3, 14, 15 };boost::array<int,3> c2 = { 1, 2, 3 };std::pair<int* , int*> ret = mismatch ( c1.begin(),     c1.end(),       c2.begin(), c2.end()) ;std::cout << "arr1 point:" << std::distance(c1.begin() , ret.first) << " arr2 point:" << std::distance(c2.begin() , ret.second)  << std::endl;// --> <c1.begin(), c2.begin()> // first elements do not matchret = mismatch ( c1.begin() + 1, c1.begin() + 4, c2.begin(), c2.end());std::cout << "arr1 point:" << std::distance(c1.begin() , ret.first)  << " arr2 point:" << std::distance(c2.begin() , ret.second) << std::endl;// --> <c1.begin() + 4, c2.end ()> // all elements of `c2` matchret = mismatch ( c1.end(),       c1.end(),       c2.end(),   c2.end());std::cout << "arr1 point:" << std::distance(c1.begin() , ret.first)  << " arr2 point:" << std::distance(c2.begin() , ret.second) << std::endl;// --> <c1.end(), c2.end()> // empty sequences don't match at the end.}



运行

=====<boost_algorithm_equal>begin[std::equal ( seq1.begin (), seq1.end (), seq2.begin ())]:[true][std::equal ( seq2.begin (), seq2.end (), seq1.begin ())]:[false][equal ( seq1.begin (), seq1.end (), seq2.begin (), seq2.end ())]:[false]=====<boost_algorithm_equal>end [State:OK] [Times:0.008s]=====<boost_algorithm_mismatch>beginarr1 point:0 arr2 point:0arr1 point:4 arr2 point:3arr1 point:6 arr2 point:3=====<boost_algorithm_mismatch>end [State:OK] [Times:0.023s]








0 0