首页 > 其他 > 详细

STL学习之mismatch();

时间:2020-01-23 23:52:22      阅读:156      评论:0      收藏:0      [点我收藏+]

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>

STL学习之mismatch();

原文:https://www.cnblogs.com/working-in-heart/p/12231635.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!