ranges::sort does not work with Qt 5 QList
Debian 11 gcc (Debian 10.2.1-6) Ranges 0.11.0 Qt 5.15.10 -std=gnu++2a
If I have code like this:
QList<int> l;
ranges::sort(l);
I get:
/somewhere/code.cpp: In function ‘QStringList {anonymous}::detail::uniqueVideoSourceTokens(const QList<vtg::onvif::OnvifMediaProfileInfo>&)’:
/somewhere/code.cpp:103:19: error: no match for call to ‘(const ranges::sort_fn) (QList<int>&)’
103 | ranges::sort(l);
| ^
In file included from /home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/range_fwd.hpp:25,
from /home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/view/filter.hpp:17,
from /somewhere/code.cpp:18:
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/algorithm/sort.hpp:201:11: note: candidate: ‘template<class I, class S, class C, class P> requires (sortable<I, C, P>) && (random_access_iterator<I>) && (sentinel_for<S, I>) I ranges::sort_fn::operator()(I, S, C, P) const’
201 | I RANGES_FUNC(sort)(I first, S end_, C pred = C{}, P proj = P{})
| ^~~~~~~~~~~
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/algorithm/sort.hpp:201:11: note: template argument deduction/substitution failed:
/somewhere/code.cpp:103:19: note: candidate expects 4 arguments, 1 provided
103 | ranges::sort(l);
| ^
In file included from /home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/range_fwd.hpp:25,
from /home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/view/filter.hpp:17,
from /somewhere/code.cpp:18:
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/algorithm/sort.hpp:218:9: note: candidate: ‘ranges::borrowed_iterator_t<Rng> ranges::sort_fn::operator()(Rng&&, C, P) const [with Rng = QList<int>&; C = ranges::less; P = ranges::identity; ranges::borrowed_iterator_t<Rng> = QList<int>::iterator]’
218 | RANGES_FUNC(sort)(Rng && rng, C pred = C{}, P proj = P{}) //
| ^~~~~~~~~~~
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/algorithm/sort.hpp:218:9: note: constraints not satisfied
In file included from /home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/range_fwd.hpp:22,
from /home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/view/filter.hpp:17,
from /somewhere/code.cpp:18:
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/iterator/concepts.hpp: In instantiation of ‘ranges::borrowed_iterator_t<Rng> ranges::sort_fn::operator()(Rng&&, C, P) const [with Rng = QList<int>&; C = ranges::less; P = ranges::identity; ranges::borrowed_iterator_t<Rng> = QList<int>::iterator]’:
/somewhere/code.cpp:103:19: required from here
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/iterator/concepts.hpp:291:5: required for the satisfaction of ‘sized_sentinel_for__requires_<S, I>’ [with S = QList<int>::iterator<int>; I = QList<int>::iterator<int>]
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/iterator/concepts.hpp:305:17: required for the satisfaction of ‘sized_sentinel_for<I, I>’ [with I = QList<int>::iterator<int>]
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/iterator/concepts.hpp:371:17: required for the satisfaction of ‘random_access_iterator<decltype (ranges::_::begin(declval<Rng&>()))>’ [with Rng = QList<int>&]
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/range/concepts.hpp:106:5: required for the satisfaction of ‘random_access_range__concept_<T>’ [with T = QList<int>&]
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/range/concepts.hpp:112:17: required for the satisfaction of ‘random_access_range<Rng>’ [with Rng = QList<int>&]
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/iterator/concepts.hpp:291:5: in requirements with ‘const S& s’, ‘const I& i’ [with _Arg = QList<int>::iterator<int>; I = QList<int>::iterator<int>; S = QList<int>::iterator<int>]
/home/user/.conan/data/range-v3/0.11.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/range/v3/iterator/concepts.hpp:291:5: note: the required expression ‘((((s - i), (i - s)), requires_<same_as<typename ranges::incrementable_traits<typename std::remove_cv<meta::_t<std::remove_reference<_Arg> > >::type>::difference_type, decltype ((s - i))> >), requires_<same_as<typename ranges::incrementable_traits<typename std::remove_cv<meta::_t<std::remove_reference<_Arg> > >::type>::difference_type, decltype ((i - s))> >)’ is invalid
291 | CPP_requires(sized_sentinel_for_,
| ^~~~~~~~~~~~
cc1plus: note: set ‘-fconcepts-diagnostics-depth=’ to at least 2 for more detail
But std::sort(l.begin(), l.end()) works.
For some reason ranges::sort does not "like" QList<>::iterator?
Qt docs states that it's random access iterator: https://doc.qt.io/qt-5/qlist-iterator.html#iterator_category-typedef
You might want to report a Qt bug about this. Then there's an elevated chance that I'll assign it to myself and fix it.
..except I might not be able to, since these problems where the result of operator- between operators is not the same as the container's difference_type are baked in the ABI.
..or if it's caused by the funny operator- that returns an iterator, that's also ABI-baked.
Okay then. This is caused by qt5 having the wrong difference_type for the iterator, which is not the same as the result of operator-. That's also ABI-baked.
@villevoutilainen so if it's (ever) fixed, it's only for Qt 7..? :/
Qt 6 is fine - there the iterator's difference_type and the result of operator- are the same, qsizetype. I was mistaken to talk about the container's difference_type above, that's not used. So this has been fixed in Qt 6, but fixing it in Qt 5 may prove to be.. ..difficult.
Oh, I forgot that I was using... Thanks @villevoutilainen .
I guess we can close this, as it's not ranges issue?