I'm learning ada and I'm trying to implement an addition overload for an enum.
Basically I want to be able to add an Integer to a Day type and get the resulting Day value. So MONDAY + 2 => WEDNESDAY.
Here is my simplified code:
procedure overload is
type Day is (
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
);
day1 : Day := Monday;
function "+" (left: Day; right: Integer) return Day is
-- how would I handle this here? I want to basically say
-- if Day + Integer > Saturday then
-- wraparound back to Sunday
return DayValue;
begin
for x in 0 .. 7 loop
Ada.text_io.put_line("Monday + " & Integer'Image(x) & " = " & Day'Image(day1 + x));
end loop;
end overload;