[fpc-devel] "Default" discussion for SmartPointers etc

Maciej Izak hnb.code at gmail.com
Thu Jul 28 16:05:34 CEST 2016

2016-07-28 14:59 GMT+02:00 Michael Van Canneyt <michael at freepascal.org>:

> Because with the exception of the ^ operator, I see no need for any special
> constructions to achieve a "nullable type", except maybe some implicit
> constructor/destructor ?

procedure with var parameter is special case, we need somehow to perform
backward compatibility and strong typing is the must. In the fact
TNullable<Integer> is proxy type to field of ^Integer type. ^ operator
exist to make life easier in comparison to C# implementation.

"default field" is not necessary for nullable types but is extremely useful
addition, more options and optimization for end user. We can exclude
completely possibility of usage ^ operator for nullable types (^ for
nullable type is just my invention). In that case calling functions like
test1 will be impossible. Just pure copy of Nullable types from C# -,- . So
you are right - ascetic version of nullable type need only management
operators (aka implicit constructor/destructor). Presented nullable type is
not "pure" copy of C# implementation, presented above implementation has
Pascal spirit and optimizations impossible to achieve in other languages.

btw. you can add

class operator Equal(A: TNullable<T>; B: T): Boolean;

to run this:

if b = 0 then
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160728/41f721f9/attachment.html>

More information about the fpc-devel mailing list