
2010/1/27 Stewart, Robert <Robert.Stewart@sig.com>:
Joachim Faulhaber wrote:
'is_sorted' is an important predicate. But it lives as an invariant to be maintained rather than a function to computed. So we have happily coded all kinds of sorted things without explicitly using and not necessarily needing it.
My question: Other than inside BOOST_ASSERTS, where do we really need is_sorted in production code. Are there convincing use cases?
That's an excellent question. I, too, foresaw its usefulness in assertions. I can imagine those doing DBC would like it, too. However, I can imagine examining file, network, or user input to ensure the data fits some ordering criteria, too.
. . . more of the (initially) asserting-the-invariant type of use. Yet, the question no longer is: Is "is_sorted" (aka is_ordered, is_creasing) an important predicate, that needs to be included into boost algorithms, because *it already is*. As Grant hinted there is boost::is_sorted in boost/detail/algorithm.hpp. Moreover std::is_sorted is in the sgi-stl and std::is_sorted will probably be in the new standard (see N3000): So is_creasing is ceasing I dare say. Remains the question, if the variants of is_[strictly_]{in_,de_}creasing are to be added as algorithms, which conjures up another intersting question: Are there criteria to be fulfilled to maintain the minimality of a set of free algorithms? Regards, Joachim