zoukankan      html  css  js  c++  java
  • STL: equal

    equal

    Compares two ranges element by element either for equality or equivalence in a sense specified by a binary predicate.

    template<class InputIterator1, class InputIterator2>
       bool equal(
          InputIterator1 _First1, 
          InputIterator1 _Last1, 
          InputIterator2 _First2
       );
    template<class InputIterator1, class InputIterator2, class BinaryPredicate>
       bool equal(
          InputIterator1 _First1, 
          InputIterator1 _Last1, 
          InputIterator2 _First2, 
          BinaryPredicate _Comp
       );
     
    Return Value

    true if and only if the ranges are identical or equivalent under the binary predicate when compared element by element; otherwise, false.

     
    Remarks

    The range to be searched must be valid; all pointers must be dereferenceable and the last position is reachable from the first by incrementation.

    The time complexity of the algorithm is linear in the number of elements contained in the range.

    The operator== used to determine the equality between elements must impose an equivalence relation between its operands.

    注:如果两个序列在[first,last)区间内相等,equal()返回true。如果第二序列的元素比较多,多出来的元素不予考虑。因此,如果我们希望保证两个序列完全相等,必须先判断其元素个数是否相等。

    if( vec1.size() == vec2.size() ) && equal( vec1.begin(), vec1.end(), vec2.begin() ) ){...}

    equal的第二个序列中元素个数必须大于等于第一个序列中元素个数。

  • 相关阅读:
    html JS 开发备忘
    C++学习备忘(一)
    博客开通备忘
    自己制作的代码生成工具AutoCoder
    C# 小技巧
    突破list存为模板为10M限制
    开博
    OpenEuler中C语言中的函数调用测试
    socket测试3
    电子公文传输系统验收4开发基础
  • 原文地址:https://www.cnblogs.com/freewater/p/2946746.html
Copyright © 2011-2022 走看看