zoukankan      html  css  js  c++  java
  • STL学习之mismatch();

    std::mismatch

    定义于头文件 <algorithm>

    一、定义:(共八种定义方式,一开始先了解两种即可)

    1.

    templateclass InputIt1, class InputIt2 >

    constexpr   std::pair<InputIt1,InputIt2>     mismatch( InputIt1 first1, InputIt1 last1,InputIt2 first2 );//constexpr关键字在很早就出来了,但是直到C++20才开始在STL中使用,所有声明之前都有

    2.

    templateclass InputIt1, class InputIt2 >

    constexpr std::pair<InputIt1,InputIt2>       mismatch( InputIt1 first1, InputIt1 last1,InputIt2 first2, InputIt2 last2 );

    这两者有什么差别呢?

    首先我们要知道正常情况下,这个函数是找到两个容器里面的值不匹配的迭代器并且返回,返回的是指向二个不相等元素的迭代器的 std::pair,对,是两个迭代器,分别指向前后两个容器。

    当没有InputIt2 last2 返回来自二个范围:一个以 [first1, last1) 定义而另一个以 [first2,last2) 定义,的首个不匹配对。若不提供 last2 ,则它指代 first2 + (last1 - first1) 。

    二、注意事项:

    对于 第一种:

    • 返回 pair<end_iter1,(iter2 + (end_ter1 - iter1))>,pair 的成员 second 等于 iter2 加上第一个序列的长度。如果第二个序列比第一个序列短,结果是未定义的。


    对于第二种:

      • 当第一个序列比第二个序列长时,返回 pair<end_iter1, (iter2 + (end_iter1 - iter1))>,所以成员 second 为 iter2 加上第一个序列的长度。
      • 当第二个序列比第一个序列长时,返回 pair<(iter1 + (end_iter2 - iter2)),end_iter2>, 所以成员 first 等于 iter1 加上第二个序列的长度。
      • 当序列的长度相等时,返回 pair<end_iter1, end_iter2>
  • 相关阅读:
    投票练习
    多条件查询
    PHP 购物车
    PHP TP模型
    PHP smarty函数
    PHP smarty复习
    PHP smarty缓存
    PHP phpcms
    php smarty查询分页
    PHP Smarty变量调节器
  • 原文地址:https://www.cnblogs.com/working-in-heart/p/12231635.html
Copyright © 2011-2022 走看看