Existence check for objects
Kristian Kilpi
kjkilpi at gmail.com
Thu Jun 14 01:53:11 PDT 2007
On Wed, 13 Jun 2007 23:32:10 +0300, Jarrett Billingsley
<kb3ctd2 at yahoo.com> wrote:
<snip>
> assert(o);
>
> This stupidly does not check that o is non-null; instead it runs the
> object's invariants. Which, if o really _is_ null, will cause an access
> violation. Whee.
>
> In this case, you have to write:
>
> assert(o !is null);
>
> Other syntaxes to run the invariant, such as "o.invariant()" or
> "o.assert()"
> have been proposed, but as usual nothing has come of it.
>
I think this deserves its own thread, again. ;)
So, I have created one: "Suggestion: "fix" assert(obj)"
More information about the Digitalmars-d
mailing list