首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::remove_copy

Defined in header <algorithm>

?

?

template< class InputIt, class OutputIt, class T > OutputIt remove_copy( InputIt first, InputIt last, OutputIt d_first, const T& value );

(1)

?

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class T > ForwardIt2 remove_copy( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, const T& value );

(2)

(since C++17)

template< class InputIt, class OutputIt, class UnaryPredicate > OutputIt remove_copy_if( InputIt first, InputIt last, OutputIt d_first, UnaryPredicate p );

(3)

?

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class UnaryPredicate > ForwardIt2 remove_copy_if( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first, UnaryPredicate p );

(4)

(since C++17)

从范围复制元素[first, last),到另一个范围,从d_first忽略满足特定标准的元素。源范围和目标范围不能重叠。

1%29忽略所有等于value...

3%29忽略谓词的所有元素。p回报true...

2,4%29与%281,3%29相同,但根据policy。此重载只参与以下情况下的过载解决方案:std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>是真的

参数

first, last

-

the range of elements to copy

d_first

-

the beginning of the destination range.

value

-

the value of the elements not to copy

policy

-

the execution policy to use. See execution policy for details.

类型要求

-输入必须符合输入器的要求。

-输出必须符合输出器的要求。

-前进1,前进2必须符合先行者的要求。

-单数预测必须满足谓词的要求。

返回值

Iterator到元素的最后一个复制元素。

复杂性

一点儿没错last - first谓词的应用。

对于执行策略的重载,如果ForwardIt1%27S值[医]类型不是MoveConstructible...

例外

带有名为ExecutionPolicy报告错误如下:

  • 如果执行作为算法一部分调用的函数,则引发异常ExecutionPolicy是其中之一标准政策,,,std::terminate叫做。对于任何其他人ExecutionPolicy,行为是由实现定义的。
  • 如果算法不能分配内存,std::bad_alloc被扔了。

可能的实施

第一版

*。

模板<类InputIt,类OutputIt,class T>OutputIt移除[医]复制%28 InputIt First,InputIt Lest,OutputIt d[医]首先,Const T&value%29{表示%28;第一%21=最后;++第一%29{if%28%21%28%2A第一==值%29%29{%2A丁[医]第一++=%2A第一;}返回d[医]第一;}

第二版

模板<类Inputit,类OutputIt,类UnaryPredicate>OutputIt删除[医]复制[医]如果%28首先输入,最后输入,输出输出d[医]第一,单预言p%29{表示%28;第一%21=最后;++第一%29{如果%28%21 p%28%2A第1%29%29{%2A丁[医]第一++=%2A第一;}返回d[医]第一;}

下面的代码输出一个字符串,同时动态擦除空格。

二次

代码语言:javascript
复制
#include <algorithm>
#include <iterator>
#include <string>
#include <iostream>
int main()
{
    std::string str = "Text with some   spaces";
    std::cout << "before: " << str << "\n";
 
    std::cout << "after:  ";
    std::remove_copy(str.begin(), str.end(),
                     std::ostream_iterator<char>(std::cout), ' ');
    std::cout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
before: Text with some   spaces
after:  Textwithsomespaces

二次

另见

removeremove_if

removes elements satisfying specific criteria (function template)

copycopy_if (C++11)

copies a range of elements to a new location (function template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com