comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: "NULL" returned by a function
Date: Fri, 08 Aug 2014 14:19:13 -0700
Date: 2014-08-08T14:19:13-07:00	[thread overview]
Message-ID: <ls3esh$e4r$1@dont-email.me> (raw)
In-Reply-To: <ls3ec1$v3q$1@speranza.aioe.org>

On 08/08/2014 02:10 PM, Victor Porton wrote:
> What if I want to make a function which returns either a value of type T or
> a value signifying "nothing" (like null pointer)?

Typically one should use a variant record with one variant for "nothing" and 
another for the value:

type Result (Has_Value : Boolean := False) is record
    case Has_Value is
    when False =>
       null;
    when True =>
       Value : T;
    end case;
end record;

-- 
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17

  reply	other threads:[~2014-08-08 21:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-08 21:10 "NULL" returned by a function Victor Porton
2014-08-08 21:19 ` Jeffrey Carter [this message]
2014-08-08 22:04   ` Victor Porton
2014-08-08 22:50     ` Jeffrey Carter
2014-08-09 12:45   ` Victor Porton
2014-08-09 15:13     ` Jeffrey Carter
2014-08-08 21:25 ` Shark8
2014-08-09 16:15 ` Maciej Sobczak
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox