最終更新日時(UTC):
が更新

履歴 編集

function template
<algorithm>

std::ranges::reverse_copy(C++20)

namespace std::ranges {
  template <bidirectional_iterator I,
            sentinel_for<I> S,
            weakly_incrementable O>
    requires indirectly_copyable<I, O>
  constexpr reverse_copy_result<I, O>
    reverse_copy(I first,
                 S last,
                 O result); // (1) C++20

  template <bidirectional_range R,
            weakly_incrementable O>
    requires indirectly_copyable<iterator_t<R>, O>
  constexpr reverse_copy_result<borrowed_iterator_t<R>, O>
    reverse_copy(R&& r,
                 O result); // (2) C++20
}

概要

要素の並びを逆にし、その結果を出力の範囲へコピーする。

事前条件

[first,last)[result,result+(last-first)) は領域が重なっていてはならない。

効果

0 以上 last - first 未満の整数 i について、*(result + (last - first) -1 - i) = *(first + i) を行うことで、[first,last) の範囲を [result,result+(last-first)) へコピーする。

戻り値

{ .in = last, .out = result + (last - first) }

計算量

正確に last - first 回代入する

使用例

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

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

  std::ranges::reverse_copy(str, std::ostream_iterator<char>(std::cout, ""));
}

出力

esrever

バージョン

言語

  • C++20

処理系

参照