On 2014-02-04 22:30:40 +0000, Walter Bright <[email protected]> said:

On 2/4/2014 4:23 AM, Michel Fortin wrote:
For the rare cases where you actually want both versions to work,

I think you're making a vast assumption that the case is rare.

When I write utility functions, I want them to work on as wide a variety of inputs as possible. Otherwise, they are not very useful.

Well, if you think it's needed I won't contradict you. But that does not bode well for the storage class solution. If you really think it's needed, then you could just double the '?' to give it a similar meaning to inout:

        Object?? passthrough(Object?? o)
        {
                // do something here
                return o;
        }

It looks elegant to me, even if I'm not convinced it is necessary.


you can write them twice or use a template (except in a virtual context), and in both cases you keep the efficiency of not checking for null when the argument is not nullable.

That's just what I wish to avoid. Consider adding more pointer types - the combinatorics quickly explode. Heck, just have two pointer parameters, and you already have 4 cases.

So you are already worried we'll have to add more pointer types? ;-)

Ok, let's have some fun: '#' means unique now. So we can have four kinds of pointers:

        Object   o1; // not-nullable & not-unique
        Object?  o2; // nullable & not-unique
        Object#  o3; // not-nullable & unique
        Object?# o4; // nullable & unique

And like above, double the marker to make it work like inout:

        Object??## passthrough(Object??## o)
        {
                // have some fun here
                return o;
        }

If you really think more pointer types will be added, then I suggest the implementation for this in the compiler be generic enough to support yes/no/maybe states for a couple of flags. Perhaps even user-defined flags for use by libraries (i.e. Dicebot's SQLEscapedString, or UnicodeNormalizedNFD, or why not PrimeNumber).

--
Michel Fortin
[email protected]
http://michelf.ca

Reply via email to