From 0d6bc4cdc89c98cd37994e9539200d7c009907e5 Mon Sep 17 00:00:00 2001 From: rexim Date: Wed, 13 Mar 2024 23:22:18 +0700 Subject: Finally! Useful Unions! --- test.adb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'test.adb') diff --git a/test.adb b/test.adb index 3c1ce14..a12a0af 100644 --- a/test.adb +++ b/test.adb @@ -4,15 +4,20 @@ with Ada.Strings; use Ada.Strings; with Ada.Containers.Vectors; procedure Test is - package Queue is new - Ada.Containers.Vectors(Index_Type => Natural, Element_Type => Integer); - Q: Queue.Vector; + type Item_Kind is (Key, Bomb, Checkpoint); + type Item(Kind: Item_Kind := Key) is record + case Kind is + when Key | Checkpoint => null; + when Bomb => + Cooldown: Integer; + end case; + end record; + type Map is array (Natural range <>) of Item; + type Map_Access is access Map; + + Items: Map_Access := null; begin - for Index in 1..10 loop - Q.Append(Index); - end loop; - while not Q.Is_Empty loop - Put_Line(Integer'Image(Q(0))); - Q.Delete_First; - end loop; + Items := new Map(1..10); + Items(1) := (Kind => Bomb, Cooldown => 10); + Put_Line(Items.all'Image); end; -- cgit v1.2.3