On 10/06/2019 02:47, Ben Grasset wrote:
Yes? Obviously? I clearly demonstrated the technical benefit in my original comment. *Yet again *though I do not understand why this is controversial. It would amount to a very tiny syntax addition, that does *nothing *other than make certain things *easier* to write.

Well a few points from my side.

Your first post (if I have it right) was about generics:
  procedure MemCopy<T>(Dest: ^T; Src: ^T; Len: PtrUInt);
A case in which the type is determined later, and you cannot (easily) declare the pointer type in advance)

To start with, I can see the appeal for that case.

Problem 1: Overloading.

program Project1;
type
  Ta = type ^byte;
  Tb = type ^byte;

procedure P1(x: Ta); overload;
begin  writeln(1); end;

procedure P1(x: Tb); overload;
begin  writeln(2); end;

begin
  P1(Ta(1));
  P1(Tb(1));
end.

If you did have "procedure P1(x: ^Byte); overload;", how would you call it?

Problem 2:
pointer to pointer?
This is not allowed in type:
  type PPFoo = ^^Foo;
But what if you need it for a param?

Problem 3:
You stated (IIRC, somewhere in this thread), this was a special case for pointers only. All the other types that can be declared are not needing this. Well, that may be true for inline record declarations, though you could call them with a constant:
   procedure P1(record a,b: Byte end); overload;
and
    P1( (a:1; b:2) );

Yes it is more far fetched. But gets closer with each step.

The possible next step, if pointers would be agreed on, might be sets. They are identical to the pointer issue. (At specialization T must substituted by an existing enum)
  procedure Foo<T>(arg: set of T);
The enum values of T are known, so this can be called.

And to extend on this, if specialization can also take constants, then ranges would be in the same category
  procedure Foo<A,B>(arg: A..B);
Actually
  type TBar = class
    const A=1; B=5;
  end
  procedure Foo<T>(arg: T.A..T.B);

So this is all, but limited to pointers.




_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to