File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
courses/fundamentals_of_ada/030_basic_types Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,37 @@ Attributes Reflect the Underlying Type
181
181
Shade : Color range Red .. Blue := Brown; -- run-time error
182
182
Hue : Rainbow := Rainbow'Succ (Blue); -- run-time error
183
183
184
+ ---------------
185
+ Valid attribute
186
+ ---------------
187
+
188
+ * :ada: `T'Valid ` is a :ada: `Boolean `
189
+ * :ada: `True ` |rightarrow | the current representation for the given scalar is valid
190
+
191
+ .. code :: Ada
192
+
193
+ procedure Main is
194
+ type Small_Odd is new Integer range 0 .. 5
195
+ with Predicate => Small_Odd mod 2 = 1;
196
+ O : aliased Small_Odd;
197
+ O_Alias : aliased Integer with Address => O'Address;
198
+ begin
199
+ for I in 0 .. 10 loop
200
+ O_Alias := I;
201
+ Ada.Text_IO.Put_Line (Boolean'Image (O'Valid));
202
+ end loop;
203
+ end Main;
204
+
205
+ .. code ::
206
+
207
+ FALSE
208
+ TRUE
209
+ FALSE
210
+ TRUE
211
+ FALSE
212
+ TRUE
213
+ FALSE
214
+
184
215
------------------------
185
216
Idiom: Extended Ranges
186
217
------------------------
You can’t perform that action at this time.
0 commit comments