comp.lang.ada
 help / color / mirror / Atom feed
* Initializing an array of tasks with discrimants
@ 2019-11-22 22:07 Jere
  2019-11-22 22:39 ` Jeffrey R. Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Jere @ 2019-11-22 22:07 UTC (permalink / raw)


I recently ran into a situation where I had an array
of tasks that had discriminants (with a default), but 
I couldn't find a simple way to initialize them.  I 
did come up with a workaround, but wanted to see if
the language defined a way to do this:

    task type T(D: Integer := 3);
    
    task body T is 
    begin 
        null; 
    end T;
    
    type A is array (Integer range <>) of T;
    
    V : A(1..10) := ?????????

If they all had the same discriminant value, I
can just create a subtype and do an array of 
the subtype, but in this case, the discriminants
would not all be the same.

My work around was a wrapper type:

    type Wrapper(D : Integer := 0) is record
        Impl : T(D);
    end record.

    type A is array (Integer range <>) of Wrapper;

    V : A(1..10) := (1 => (D => 1, others => <>), and so on

But I was hoping there was a better way to do it simply.
The Wrapper record isn't there to represent the 
intended design and doesn't really improve readability.
It's essentially a workaround for something I cannot 
figure out.

I tried many variations of qualified expressions and 
aggregates on the original task type elements, but all
of them gave me errors about it expected the task type
but found a composite type instead.

Is there a particular aggregate that I can use to avoid
the superfluous wrapper record?


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

end of thread, other threads:[~2019-11-25 22:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22 22:07 Initializing an array of tasks with discrimants Jere
2019-11-22 22:39 ` Jeffrey R. Carter
2019-11-23 16:23   ` Jere
2019-11-22 23:57 ` Robert A Duff
2019-11-23  0:27   ` Anh Vo
2019-11-23  9:12   ` Randy Brukardt
2019-11-23 16:50     ` Jere
2019-11-23 16:25   ` Jere
2019-11-23  8:29 ` Dmitry A. Kazakov
2019-11-23 16:28   ` Jere
2019-11-23 17:03     ` Dmitry A. Kazakov
2019-11-23 16:57 ` Jere
2019-11-25 22:36   ` Randy Brukardt

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