Numeric types sec are ordinals (of course not float types)
We already have constraints for classes and records.
My outstanding feature request is about just ordinals, which includes by their very nature all integer types and enumerations. It is well received.
So where we can now already limit a generic to a class or record, we would be able to write somegeneric<T:Ordinal> which makes it type safe for any type that can be expressed as an ordinal.
(e.g.: ordinal, enumeration, numeric?)
All of these fall in the
category ordinal. It would be the
specialization that determines what kind of ordinal, just as with class and record restrictions.
I have not thought about a float restriction. I see less use for it. Floats have only one typekind, just tkFloat, which can easily be handled by overloads. Ordinal values have multiple typekinds. See:
https://www.freepascal.org/docs-html/rtl/system/ttypekind.htmlAlthough in both cases you can already do things like this:
generic function testme<T>(const value:T):T;
begin
Assert(GetTypeKind(value)= tkFloat,'is not a float');
//work with T
end;