3 ms·
> What are sort’s preconditions? 1. The first and last iterators must point at elements from the same container. 2. first must not indicate an element that appe
by WalterBright 2y ago
> What are sort’s preconditions?
1. The first and last iterators must point at elements from the same container.
2. first must not indicate an element that appears after last.
3. first and last may not be dangling iterators.
This is a fundamental problem in C++ where a range is specified by the starting point and the ending point. This is because iterators in C++ are abstractions of a pointer.
D took a different approach. A range in D is an abstraction of an array. An array is specified by its starting point and its length. This inherently solves points one and two (not sure about three).
Sort then has a prototype of:
Range sort(Range);