comp.lang.ada
 help / color / mirror / Atom feed
* Choice of variant record discriminant (design question)
@ 2005-10-26 12:21 Jacob Sparre Andersen
  2005-10-26 13:14 ` christoph.grein
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jacob Sparre Andersen @ 2005-10-26 12:21 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-10-31 15:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-26 12:21 Choice of variant record discriminant (design question) Jacob Sparre Andersen
2005-10-26 13:14 ` 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

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