https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107367
Bug ID: 107367 Summary: All standard library algorithms should detect whether they are contiguous iterators after C++20 Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: unlvsur at live dot com Target Milestone: --- https://github.com/gcc-mirror/gcc/blob/00716b776200c2de6813ce706d2757eec4cb2735/libstdc%2B%2B-v3/include/bits/stl_algo.h#L3229 Take is_sorted for example: template<typename _ForwardIterator> _GLIBCXX20_CONSTEXPR inline bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { return std::is_sorted_until(__first, __last) == __last; } It should be optimized to template<typename _ForwardIterator> _GLIBCXX20_CONSTEXPR inline bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { if constexpr(contiguous_iterator<_ForwardIterator>&&!is_pointer_v<_ForwardIterator>) { return is_sorted(to_address(__first),to_address(__last)); } else { return std::is_sorted_until(__first, __last) == __last; } }