std::sortable

std::sortable (정렬 가능 컨셉)

Comp에 따라 범위를 정렬된 범위로 순열 변환하는 알고리즘에 대한 요구사항을 명세하는 컨셉이에요. C++20부터 있어요.

출처: cppreference

본문

<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>>;

sortable 컨셉은 Comp에 따라 범위를 정렬된 범위로 순열 변환하는 알고리즘에 대한 요구사항을 명세해요. 요소를 이동·교환할 수 있고(permutable), projection을 적용한 값들이 엄밀 약순서를 갖는(indirect_strict_weak_order) 것을 요구해요. sort, partial_sort, nth_element, stable_sort 등에 필요한 요구사항이에요.

의미 요구사항

std::sortable<I, Comp, Proj>은 그것이 포함하는 모든 컨셉이 모델링될 때만 모델링돼요.

예제

#include <iterator>
#include <vector>
#include <concepts>

int main()
{
    static_assert(std::sortable<std::vector<int>::iterator>);
}

더 알아보기 (Learn more)

cppreference