dsimcha wrote:
== Quote from Andrei Alexandrescu ([email protected])'s articleI think the stability request could be better encoded as a wrapper of the range making the request. For example: auto p = partition!("(a & 1) == 0")(keepStable(arr)); So in order to tell partition you want stability, you just wrap the range with a call to keepStable. (The runtime cost is negligible). Similarly, say you want a stable sort. You'd say: sort(keepStable(arr)); instead of: sort!(SwapStrategy.stable)(arr);Can you elaborate a little? In particular, would the KeepStable wrapper actually _do_ anything in itself to make modifications to the underlying range stable, or would it just wrap the range in a new type so that you could stick a static if statement in the sort algorithm to decide what to?
keepStable is a template function that simply wraps the range in a different type. It's a way to pass information about the range (e.g., "keep this stable", or "this is sorted already"), to the function understanding it.
Andrei
