Overview of Ada 2022
7.6 Aggregates and variant parts
Aggregates and variant
parts (AI12-0086)
allows a discriminant that controls a variant in an aggregate to be non-static
if the subtype of the discriminant is static and all values belonging
to that subtype select the same variant (see RM
4.3.1).
For example:
type Enum is (Aa, Bb, Cc, ..., Zz);
subtype S is Enum range Dd .. Hh;
type Rec (D : Enum) is record
case D is
when S => Foo,
Bar : Integer;
when others =>
null;
end case;
end record;
function Make (D : S) return Rec is
begin
return (D => D, Foo => 123, Bar => 456);
end;
© 2021, 2022 Jeff Cousins