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

std::rotate_copy

Defined in header <algorithm>

template< class ForwardIt, class OutputIt > OutputIt rotate_copy( ForwardIt first, ForwardIt n_first, ForwardIt last, OutputIt d_first );

(1)

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2 > ForwardIt2 rotate_copy( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 n_first, ForwardIt1 last, ForwardIt2 d_first );

(2)

(since C++17)

1%29拷贝范围内的元素[first, last),到另一个范围,从d_first以这样的方式,元素n_first成为新范围的第一个元素,并且n_first - 1成为最后一个元素。

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

参数

first, last

-

the range of elements to copy

n_first

-

an iterator to an element in [first, last) that should appear at the beginning of the new range

d_first

-

beginning of the destination range

policy

-

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

类型要求

-前进,前进1,前进2必须满足先行者的要求。

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

返回值

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

例外

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

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

可能的实施

模板<类向前,类输出它>输出它旋转[医]复制%28 ForwardIt First,Forwardit n[医]第一,向前,最后,输出d[医]第一%29{d[医]First=STD::拷贝%28N[医]第一,最后,d[医]第一%29;返回STD::复制%281,n[医]第一,d[医]第一%29;}

*。

二次

代码语言:javascript
复制
#include <algorithm>
#include <vector>
#include <iostream>
 
int main()
{
    std::vector<int> src = {1, 2, 3, 4, 5}; 
    auto pivot = std::find(src.begin(), src.end(), 3); 
    std::vector<int> dest(src.size());                                          
 
    std::rotate_copy(src.begin(), pivot, src.end(), dest.begin());
 
    for (const auto &i : dest) {
        std::cout << i << ' ';
    }   
    std::cout << '\n';
}

二次

产出:

二次

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

二次

复杂性

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

另见

rotate

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

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

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

扫码关注腾讯云开发者

领取腾讯云代金券