Skip to content

Instantly share code, notes, and snippets.

@ytomino
Created July 30, 2014 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytomino/91a5c77e7c9316e2aee3 to your computer and use it in GitHub Desktop.
Save ytomino/91a5c77e7c9316e2aee3 to your computer and use it in GitHub Desktop.
コンパイル時に結果をチェックできる引き算
package dtmodoki is
-- minus functions ensuring Left >= Right (Left - Right >= 0)
generic
X : Natural;
Y : Natural;
package Natural_Minus is
subtype Result is Natural range X - Y .. X - Y;
function F return Result is (X - Y);
end Natural_Minus;
package Calc_5_Minus_3 is new Natural_Minus (5, 3); -- OK
package Calc_3_Minus_5 is new Natural_Minus (3, 5); -- warned
--dtmodoki.ads:19:04: warning: in instantiation at line 9
--dtmodoki.ads:19:04: warning: static value out of range of type "Standard.Natural"
--dtmodoki.ads:19:04: warning: "Constraint_Error" will be raised at run time
end dtmodoki;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment