20.02.2016, 02:05, "Sven Barth" <pascaldra...@googlemail.com>:
> There's no need for a sample. This degradation is the whole reason why the 
> non-generic classes TFPObjectList and TFPList exist compared to TObjectList 
> and TList which do have notifications.
>
> Regards,
> Sven

/ My previous mail appeared to be in html format. Sorry for that.

Hi

That always keeps me wondering - why neither FPC, no any other mainstream 
static-type language implements specialization based not only on types, but on 
compile-time constants as well?

I mean something like

  TGenericList<T,options> = class
    ...
  end;

procedure TGenericList<T,options>.Delete(index:integer);
begin
  if (nnNotifyDelete in options) and Assigned(FOnDelete) then
    FOnDelete(...);
  end;
end;

// usage
type
  TMyList = specialize TGenericList<integer, [nnNotifyAdd, nnNotifyDelete, 
nnNotifyChange]>;

... that "if (nnNotifyDelete in options) " condition will optimized out by 
compiler if options lack corresponding enum constant.
Of course, FOnDelete property should be omitted as well in ideal case. That 
might require something like "static if" in D.

I've done that trick for ages using m4 preprocessor and it works really good, 
why it's still not supported natively by compilers themselves?

-- 
Regards,
Denis Golovan
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to