# std::sortable

> C++ Atlas: `cppatlas.com/w/cpp/iterator/sortable` | Source: https://en.cppreference.com/w/cpp/iterator/sortable | Domain: Iterator | Standards: C++20

The sortable concept specifies the requirements for algorithms that permute a range into an ordered range according to Comp.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <iterator>

template< class I, class Comp = ranges::less, class Proj = std::identity >
concept sortable =
    std::permutable<I> &&
    std::indirect_strict_weak_order<Comp, std::projected<I, Proj>>; // (since C++20)
```

The `sortable` concept specifies the requirements for algorithms that permute a range into an ordered range according to `Comp`.

### Semantic requirements

`std::sortable<I, Comp, Proj>` is modeled only if all concepts it subsumes are modeled.

### See also

- [`ranges::sort`](https://en.cppreference.com/w/cpp/algorithm/ranges/sort) (C++20): sorts a range into ascending order (algorithm function object)
- [`ranges::stable_sort`](https://en.cppreference.com/w/cpp/algorithm/ranges/stable_sort) (C++20): sorts a range of elements while preserving order between equal elements (algorithm function object)
- [`ranges::partial_sort`](https://en.cppreference.com/w/cpp/algorithm/ranges/partial_sort) (C++20): sorts the first N elements of a range (algorithm function object)
- [`ranges::nth_element`](https://en.cppreference.com/w/cpp/algorithm/ranges/nth_element) (C++20): partially sorts the given range making sure that it is partitioned by the given element (algorithm function object)
- [`ranges::inplace_merge`](https://en.cppreference.com/w/cpp/algorithm/ranges/inplace_merge) (C++20): merges two ordered ranges in-place (algorithm function object)
- [`ranges::push_heap`](https://en.cppreference.com/w/cpp/algorithm/ranges/push_heap) (C++20): adds an element to a max heap (algorithm function object)
- [`ranges::pop_heap`](https://en.cppreference.com/w/cpp/algorithm/ranges/pop_heap) (C++20): removes the largest element from a max heap (algorithm function object)
- [`ranges::make_heap`](https://en.cppreference.com/w/cpp/algorithm/ranges/make_heap) (C++20): creates a max heap out of a range of elements (algorithm function object)
- [`ranges::sort_heap`](https://en.cppreference.com/w/cpp/algorithm/ranges/sort_heap) (C++20): turns a max heap into a range of elements sorted in ascending order (algorithm function object)
- [`ranges::next_permutation`](https://en.cppreference.com/w/cpp/algorithm/ranges/next_permutation) (C++20): generates the next greater lexicographic permutation of a range of elements (algorithm function object)
- [`ranges::prev_permutation`](https://en.cppreference.com/w/cpp/algorithm/ranges/prev_permutation) (C++20): generates the next smaller lexicographic permutation of a range of elements (algorithm function object)

---
Attribution: content from https://en.cppreference.com/w/cpp/iterator/sortable (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.