GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::rotate_copy - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. algorithm
  3. rotate_copy

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<algorithm>

std::rotate_copy

namespace std {
  template <class ForwardIterator, class OutputIterator>
  OutputIterator
    rotate_copy(ForwardIterator first,
                ForwardIterator middle,
                ForwardIterator last,
                OutputIterator result);   // (1) C++98

  template <class ForwardIterator, class OutputIterator>
  constexpr OutputIterator
    rotate_copy(ForwardIterator first,
                ForwardIterator middle,
                ForwardIterator last,
                OutputIterator result);   // (1) C++20

  template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
  ForwardIterator2
    rotate_copy(ExecutionPolicy&& exec,
                ForwardIterator1 first,
                ForwardIterator1 middle,
                ForwardIterator1 last,
                ForwardIterator2 result); // (2) C++17
}

概要

middleの要素が先頭、middle-1の要素が末尾となるように、イテレータ範囲[first,last)の要素の並びを回転させ、その結果を出力の範囲へコピーする。

事前条件

  • [first,last) と [result,result + (last - first)) の範囲は重なっていてはならない

効果

0 以上 last - first 未満の整数 i について、*(result + i) = *(first + (i + (middle - first)) % (last - first)) という操作によって [first,last) の範囲を [result,result + (last - first)) の範囲へコピーする

戻り値

出力範囲の終端を指すイテレータresult + (last - first)

計算量

正確に last - first 回代入する。

例

#include <algorithm>
#include <iostream>
#include <string>
#include <iterator>

int main() {
  std::string str = "rotate";
  std::string result;

  std::rotate_copy(str.begin(), str.begin() + 2, str.end(),
    std::back_inserter(result));

  std::cout << result << std::endl;
}

出力

tatero

実装例

template <class ForwardIterator, class OutputIterator>
OutputIterator rotate_copy(ForwardIterator first,
                           ForwardIterator middle,
                           ForwardIterator last,
                           OutputIterator result) {
  return std::copy(first, middle, std::copy(middle, last, result));
}

関連項目

  • ranges::rotate_copy

参照

  • P0202R3 Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers
  • P0467R2 Iterator Concerns for Parallel Algorithms
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.