with Ada.Containers.Ordered_Maps; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; procedure MapIterateCheck is -- Instantiate the generic package Ada.Containers.Ordered_Maps package Associative_Int is new Ada.Containers.Ordered_Maps(Unbounded_String, Integer); use Associative_Int; Color_Map : Map; Color_Cursor : Cursor; Success : Boolean; Value : Integer; TheKey: Unbounded_String; begin -- Add values to the ordered map Color_Map.Insert(To_Unbounded_String("Red"), 10, Color_Cursor, Success); Color_Map.Insert(To_Unbounded_String("Blue"), 20, Color_Cursor, Success); Color_Map.Insert(To_Unbounded_String("Yellow"), 5, Color_Cursor, Success); -- retrieve values from the ordered map and print the value and key -- to the screen Value := Color_Map.Element(To_Unbounded_String("Red")); Ada.Text_Io.Put_Line("Red:" & Integer'Image(Value)); Value := Color_Map.Element(To_Unbounded_String("Blue")); Ada.Text_IO.Put_Line("Blue:" & Integer'Image(Value)); Value := Color_Map.Element(To_Unbounded_String("Yellow")); Ada.Text_IO.Put_Line("Yellow:" & Integer'Image(Value)); -- Output isn't ordered. Must use Ada cursor (iterator) to get ordered Ada.Text_IO.Put_Line("Now, with Ada's version of Iterators..."); Color_Cursor := First(Color_Map); while Has_Element(Color_Cursor) loop TheKey := Key(Color_Cursor); Value := Element(Color_Cursor); Ada.Text_IO.Put_Line(To_String(TheKey) & "=" & Integer'Image(Value)); Next(Color_Cursor); end loop; -- Query the map if Contains(Color_Map,To_Unbounded_String("Red")) Then -- Will Print this Ada.Text_IO.Put_Line("Red is in the Map"); end if; if Contains(Color_Map,To_Unbounded_String("Magenta")) Then -- Will NOT Print this Ada.Text_IO.Put_Line("Magenta is in the Map"); end if; end MapIterateCheck;