I wrote my own Matrix and Iterator class for it. The assignment requires the support of the standard library (std::find, std::sort int STL). With std::find it works fine, but std::sort doesn't anymore. What is the problem with my iterator? Here is an example of work: https://godbolt.org/z/zdqaj6ddY
Asked
Active
Viewed 29 times
0
-
3`std::sort` requires [random access iterators](https://en.cppreference.com/w/cpp/iterator/random_access_iterator). Your iterator appears to be an [input iterator](https://en.cppreference.com/w/cpp/iterator/input_iterator). You'll need to improve your iterator so that it satisfies the requirements for a random access iterator to use it with `std::sort`. – François Andrieux May 27 '22 at 21:16
-
Thanks, can you tell me which functions from the standard library the input iterator works with? – Елизавета Тараненко May 27 '22 at 21:25
-
@ЕлизаветаТараненко On top of what you already have, Just `operator<`, I believe (however you would define that for a matrix). – Paul Sanders May 27 '22 at 23:31
-
[This](https://www.internalpointers.com/post/writing-custom-iterators-modern-cpp) article covers it pretty nicely. Also, you may want to have a look [here](https://stackoverflow.com/questions/3582608/how-to-correctly-implement-custom-iterators-and-const-iterators). – alagner May 28 '22 at 11:18