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

std::reverse_copy

Defined in header <algorithm>

?

?

template< class BidirIt, class OutputIt > OutputIt reverse_copy( BidirIt first, BidirIt last, OutputIt d_first );

(1)

?

template< class ExecutionPolicy, class BidirIt, class ForwardIt > ForwardIt reverse_copy( ExecutionPolicy&& policy, BidirIt first, BidirIt last, ForwardIt d_first );

(2)

(since C++17)

1%29拷贝范围内的元素[first, last)到另一个范围,从d_first在这种情况下,新范围内的元素是相反的。

行为似乎是通过执行赋值来执行的。*(d_first + (last - first) - 1 - i) = *(first + i)每一次非阴性i < (last - first)

如果源和目标范围为%28,即,[first, last)[d_first, d_first+(last-first))分别%29重叠,行为未定义。

2%29与%281%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

类型要求

-Bidirit必须符合双向迭代器的要求。

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

---。

返回值

将迭代器输出到上一个复制元素之后的元素。

例外

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

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

可能的实施

模板<类Bidirit,类OutputIt>OutputIt反向[医]复制%28 Bidirit--先复制,Bidiit最后复制,Outputit d[医]第一%29{而%281%21=最后%29{%2A%28d[医]第一++%29=%2A%28--最后%29;}返回d[医]第一;}

*。

二次

代码语言:javascript
复制
#include <vector>
#include <iostream>
#include <algorithm>
 
int main()
{
    std::vector<int> v({1,2,3});
    for (const auto& value : v) {
        std::cout << value << " ";
    }
    std::cout << '\n';
 
    std::vector<int> destination(3);
    std::reverse_copy(std::begin(v), std::end(v), std::begin(destination));
    for (const auto& value : destination) {
        std::cout << value << " ";
    }
    std::cout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
1 2 3 
3 2 1

二次

复杂性

直线在之间的距离firstlast...

另见

reverse

reverses the order of elements in a range (function template)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com