From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Choice of variant record discriminant (design question)
Date: Wed, 26 Oct 2005 14:21:53 +0200
Date: 2005-10-26T14:21:53+02:00 [thread overview]
Message-ID: <m2acgwmpsu.fsf@hugin.crs4.it> (raw)
I have declared a record type like this:
type Preprocessed_Parameters (Measurement_Count : Natural := 0) is
record
case Measurement_Count is
when 0 =>
null;
when others =>
Mean_Value : Scalar;
Scaled_Variance : Scalar;
end case;
end record;
I would like to return an object of that type from a function using
this piece of code:
if Count = 0 then
return (Measurement_Count => 0);
else
[...]
return (Measurement_Count => Count,
Mean_Value => Mean,
Scaled_Variance => Sum);
end if;
I can't do this, since the discriminant has to be static. The obvious
solution to the problem is to change the record declaration into:
type Preprocessed_Parameters (Empty : Boolean := True) is
record
case Empty is
when True =>
null;
when False =>
Measurement_Count : Positive;
Mean_Value : Scalar;
Scaled_Variance : Scalar;
end case;
end record;
but I have a feeling there ought to be a more elegant solution. Does
somebody have a suggestion or two?
Jacob
--
ACRONYM: A Contrived Reduction Of Nomenclature Yielding Mnemonics
next reply other threads:[~2005-10-26 12:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-26 12:21 Jacob Sparre Andersen [this message]
2005-10-26 13:14 ` Choice of variant record discriminant (design question) christoph.grein
2005-10-26 13:26 ` Jacob Sparre Andersen
2005-10-26 17:52 ` Jeffrey R. Carter
2005-10-26 19:52 ` Randy Brukardt
2005-10-31 15:53 ` Jacob Sparre Andersen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox