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

履歴 編集

function template
<algorithm>

std::is_sorted(C++11)

namespace std {
  template <class ForwardIterator>
  bool is_sorted(ForwardIterator first,
                 ForwardIterator last);           // (1) C++11

  template <class ForwardIterator>
  constexpr bool is_sorted(ForwardIterator first,
                           ForwardIterator last); // (1) C++20

  template <class ForwardIterator, class Compare>
  bool is_sorted(ForwardIterator first,
                 ForwardIterator last,
                 Compare comp);                   // (2) C++11

  template <class ForwardIterator, class Compare>
  constexpr bool is_sorted(ForwardIterator first,
                           ForwardIterator last,
                           Compare comp);         // (2) C++20

  template <class ExecutionPolicy, class ForwardIterator>
  bool is_sorted(ExecutionPolicy&& exec,
                 ForwardIterator first,
                 ForwardIterator last);           // (3) C++17

  template <class ExecutionPolicy, class ForwardIterator, class Compare>
  bool is_sorted(ExecutionPolicy&& exec,
                 ForwardIterator first,
                 ForwardIterator last,
                 Compare comp);                   // (4) C++17
}

概要

イテレータ範囲[first, last)がソート済みか判定する。

戻り値

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  std::vector<int> v = {3, 1, 4, 2, 5};

  std::cout << std::boolalpha;
  std::cout << "before: is sorted? " << std::is_sorted(v.begin(), v.end()) << std::endl;

  std::sort(v.begin(), v.end());

  std::cout << " after: is sorted? " << std::is_sorted(v.begin(), v.end()) << std::endl;
}

出力

before: is sorted? false
 after: is sorted? true

バージョン

言語

  • C++11

処理系

  • Clang: ??
  • GCC: 4.7.0
  • ICC: ??
  • Visual C++: 2010, 2012, 2013, 2015
    • 2008では、_HAS_TRADITIONAL_STLを1に定義してから<algorithm>をインクルードすると、stdext名前空間でis_sortedが定義される。

参照