Yep.
And sometimes it's hype over the weirdest things... a good example "dependency injection".
Generic
Type Index is (<>); -- Any discrete type.
Type Element is limited private; -- Any non-discriminated type.
Type Vector is array(index range <>) of element; -- An array-type of Element, indexed by Index.
with Function "="(Left, Right: Element) return Boolean <>; -- Equal, defaulted.
with Function "<"(Left, Right: Element) return Boolean <>; -- Less-than, defaulted.
Function Generic_Sort( X : Vector ) return Vector;
Now when we instantiate we can inject '>' in place of the '<', reversing the direction of the sort:
Function Sort is new Generic_Sort( Index => Integer, Element => Integer, Vector => Integer_Array, "<" => ">");
Yep. And sometimes it's hype over the weirdest things... a good example "dependency injection".
Now when we instantiate we can inject '>' in place of the '<', reversing the direction of the sort: