--  Rectangular aggregates of named rows over more positions than are built one by one
--  (more than 1024), within bounds known at run time: a range of rows is put in place by a
--  loop whose invariant says what it has put (D257); and subtype choices, a qualified
--  aggregate taking its subtype's bounds.
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   function Id (X : Integer) return Integer is (X);
   type Grid is array (Integer range <>, Integer range <>) of Integer;
   subtype Big is Grid (1 .. Id (2000), 1 .. Id (3));
   G : constant Big := (1 .. 1000 => (others => 1), 1001 .. 2000 => (others => 2));
   H : constant Big := (5 => (others => 9), 1500 .. 1600 => (others => 8), others => (others => 3));
   subtype Middle is Integer range 1200 .. 1300;
   J : constant Big := (Middle => (others => 4), others => (others => 5));
   B : constant array (Boolean, Integer range 1 .. Id (3)) of Integer := (Boolean => (others => 6));
   type Row is array (Positive range <>) of Integer;
   subtype Four is Row (1 .. Id (4));
   function Sum (R : Row) return Integer is (if R'Length = 4 then R (R'First) else 0);
   subtype Two is Positive range 2 .. 3;
   procedure Show (N : Positive) is
      A : constant Row (1 .. N) := (Two => 1, others => 0);
   begin
      Put_Line (Integer'Image (A (1)) & Integer'Image (A (2)) & Integer'Image (A (3)) & Integer'Image (A'Length));
   end Show;
begin
   pragma Assert (G (1000, 1) = 1 and G (1001, 3) = 2);
   pragma Assert (H (5, 2) = 9 and H (1, 1) = 3 and H (2000, 3) = 3);
   pragma Assert (J (1250, 2) = 4 and J (1301, 1) = 5);
   pragma Assert (B (True, 3) = 6);
   Put_Line (Integer'Image (G (1000, 1)) & Integer'Image (G (1001, 3)) & Integer'Image (H (1600, 1)) & Integer'Image (H (1601, 1)) & Integer'Image (J (1200, 3)) & Integer'Image (J (1199, 3)));
   Put_Line (Integer'Image (Sum (Four'(others => 3))));
   Show (5);
end Main;
