difference

更新时间:2022-11-24 17:57:08 阅读: 评论:0


2022年11月24日发(作者:卢沟桥七七事变)

std::t_difference⽤法

描述:拷贝容器1中的元素到容器3中,且该元素不在容器2中。使⽤该函数前,两个容器需要⽤std::sort先排序。

定义:

可能的实现:

参数:first1,last1-容器1范围first2,last2-容器2范围d_first-⽬标容器范围的起始位置

返回值:返回构造的范围的尾后迭代器。

⽰例:

template

OutputItt_difference(InputIt1first1,InputIt1last1,

InputIt2first2,InputIt2last2,

OutputItd_first);

template

constexprOutputItt_difference(InputIt1first1,InputIt1last1,

InputIt2first2,InputIt2last2,

OutputItd_first);

1

2

3

4

5

6

7

8

9

template

OutputItt_difference(InputIt1first1,InputIt1last1,

InputIt2first2,InputIt2last2,

OutputItd_first)

{

while(first1!=last1)

{

if(first2==last2)

returnstd::copy(first1,last1,d_first);

if(*first1<*first2)

{

*d_first++=*first1++;

}

el

{

if(!(*first2<*first1))

{

++first1;

}

++first2;

}

}

returnd_first;

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

#include

#include

#include

#include

intmain()

{

std::vectorv1{1,2,5,5,5,9};

std::vectorv2{2,5,7};

std::vectordiff;

std::t_difference((),(),(),(),

std::inrter(diff,()));

for(autoi:diff)std::cout<

std::cout<<'n';

//1559

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

本文发布于:2022-11-24 17:57:08,感谢您对本站的认可!

本文链接:http://www.wtabcd.cn/fanwen/fan/90/13357.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

下一篇:bestones
标签:difference
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图