# 28 Algorithms library [algorithms]

## 28.7 Sorting and related operations [alg.sorting]

### 28.7.1 Sorting [alg.sort]

#### 28.7.1.5is_­sorted[is.sorted]

```template<class ForwardIterator> bool is_sorted(ForwardIterator first, ForwardIterator last); ```

Returns: is_­sorted_­until(first, last) == last

```template<class ExecutionPolicy, class ForwardIterator> bool is_sorted(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last); ```

Returns: is_­sorted_­until(std​::​forward<ExecutionPolicy>(exec), first, last) == last

```template<class ForwardIterator, class Compare> bool is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); ```

Returns: is_­sorted_­until(first, last, comp) == last

```template<class ExecutionPolicy, class ForwardIterator, class Compare> bool is_sorted(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Compare comp); ```

Returns:

`is_sorted_until(std::forward<ExecutionPolicy>(exec), first, last, comp) == last`

```template<class ForwardIterator> ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator is_sorted_until(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last); template<class ForwardIterator, class Compare> ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); template<class ExecutionPolicy, class ForwardIterator, class Compare> ForwardIterator is_sorted_until(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Compare comp); ```

Returns: If (last - first) < 2, returns last. Otherwise, returns the last iterator i in [first, last] for which the range [first, i) is sorted.

Complexity: Linear.