[fpc-pascal] Comparison operator for generics

Ryan Joseph ryan at thealchemistguild.com
Tue Sep 12 06:18:48 CEST 2017

This is a common pattern I’m finding when working with generics in FPC. In the example below there is an equals comparison that needs to be checked but for some types such as records there is no default operator overload so I need to add one for every record that will be specialized in the class.

Is there a way around this? I’d like to just skip the comparison for specialized types that can’t be compared if possible.

	generic TCollection<T> = class
		procedure AddValue (value: T);

procedure TCollection.AddValue (value: T);
	// comparison operator doesn't exist for records so I get compiler errors if I specialize TCollection<> with a record type
	if value = T then

	Ryan Joseph

More information about the fpc-pascal mailing list